title: Typescript: Object is possibly 'undefined'
body: <p>I'm curious as to why I would be getting a Typescript warning below.</p>
  <p>There error appears on this line: <code>a[k].toString().toLowerCase()</code></p>
  <p>However I have the check <code>if (a &amp;&amp; a[k])</code> which should ensure that in the next line, <code>a</code> and <code>a[k]</code> cannot be undefined?</p>
  <pre><code>// Return coins that match text search by currency symbol or name.
  export const findAsset = (txt: string, assets: IAsset[] | null[]) =&gt; {
    // assets will exist here...
    if (assets) {
      // Typescript error here...
      const checkText = (k: string, a: IAsset | null) =&gt; {
        if (a &amp;&amp; a[k]) {
          return (textMatch(txt.toLowerCase(), a[k].toString().toLowerCase()) ? a : null);
        }
      }
      const curriedCheckText = R.curry(checkText);
      const byName = R.map(curriedCheckText('name'), assets);
      const bySymbol = R.map(curriedCheckText('currency'), assets);
      const matchNames = R.reject(R.isNil, byName);
      const matchSymbols = R.reject(R.isNil, bySymbol);
      const combinedSearch = (matchNames.concat(matchSymbols));
      return R.uniq(combinedSearch);
    }
    else {
      return [];
    }
  };
  </code></pre>
  <p>This is the shape of the <code>IAsset</code> interface</p>
  <pre><code>export interface IAsset {
    [key: string]: string | number | undefined | boolean;
    availableSupply?: string;
    currency: string;
    exchange: string;
    exchange_base?: string;
    marketCap: number;
    name: string;
    percentage?: number;
    price: number;
    position?: number;
    value?: number;
    inWatchlist?: boolean;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/SEAyk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SEAyk.png" alt="enter image description here" /></a></p>
  <h2>tsconfig</h2>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      /* Basic Options */
      &quot;target&quot;: &quot;es5&quot; /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
      &quot;module&quot;: &quot;commonjs&quot; /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
      &quot;lib&quot;: [
        &quot;dom&quot;,
        &quot;es2015&quot;,
        &quot;es2016&quot;,
        &quot;es2017&quot;,
      ], /* Specify library files to be included in the compilation. */,
      &quot;allowJs&quot;: true,                       /* Allow javascript files to be compiled. */
      &quot;checkJs&quot;: true,                       /* Report errors in .js files. */
      &quot;jsx&quot;: &quot;react&quot;,                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
      &quot;declaration&quot;: true,                   /* Generates corresponding '.d.ts' file. */
      &quot;declarationMap&quot;: true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */
      &quot;sourceMap&quot;: true,                     /* Generates corresponding '.map' file. */
      // &quot;outFile&quot;: &quot;./&quot;,                       /* Concatenate and emit output to single file. */
      // &quot;outDir&quot;: &quot;./&quot;,                        /* Redirect output structure to the directory. */
      // &quot;rootDir&quot;: &quot;./&quot;,                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
      // &quot;composite&quot;: true,                     /* Enable project compilation */
      // &quot;removeComments&quot;: true,                /* Do not emit comments to output. */
      &quot;noEmit&quot;: true,                        /* Do not emit outputs. */
      // &quot;importHelpers&quot;: true,                 /* Import emit helpers from 'tslib'. */
      &quot;resolveJsonModule&quot;: true,
      &quot;downlevelIteration&quot;: true,            /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
      // &quot;isolatedModules&quot;: true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
  
      /* Strict Type-Checking Options */
      &quot;strict&quot;: true /* Enable all strict type-checking options. */,
      &quot;noImplicitAny&quot;: true /* Raise error on expressions and declarations with an implied 'any' type. */,
      &quot;strictNullChecks&quot;: true /* Enable strict null checks. */,
      &quot;strictFunctionTypes&quot;: true /* Enable strict checking of function types. */,
      &quot;strictBindCallApply&quot;: true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
      &quot;strictPropertyInitialization&quot;: true /* Enable strict checking of property initialization in classes. */,
      &quot;noImplicitThis&quot;: true /* Raise error on 'this' expressions with an implied 'any' type. */,
      &quot;alwaysStrict&quot;: true /* Parse in strict mode and emit &quot;use strict&quot; for each source file. */,
  
      /* Additional Checks */
      // &quot;noUnusedLocals&quot;: true,                /* Report errors on unused locals. */
      // &quot;noUnusedParameters&quot;: true,            /* Report errors on unused parameters. */
      // &quot;noImplicitReturns&quot;: true,             /* Report error when not all code paths in function return a value. */
      // &quot;noFallthroughCasesInSwitch&quot;: true,    /* Report errors for fallthrough cases in switch statement. */
  
      /* Module Resolution Options */
      // &quot;moduleResolution&quot;: &quot;node&quot;,            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
      // &quot;baseUrl&quot;: &quot;./&quot;,                       /* Base directory to resolve non-absolute module names. */
      // &quot;paths&quot;: {},                           /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
      // &quot;rootDirs&quot;: [],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
      // &quot;typeRoots&quot;: [],                       /* List of folders to include type definitions from. */
      // &quot;types&quot;: [],                           /* Type declaration files to be included in compilation. */
      // &quot;allowSyntheticDefaultImports&quot;: true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
      &quot;esModuleInterop&quot;: true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
      // &quot;preserveSymlinks&quot;: true,              /* Do not resolve the real path of symlinks. */
  
      /* Source Map Options */
      // &quot;sourceRoot&quot;: &quot;&quot;,                      /* Specify the location where debugger should locate TypeScript files instead of source locations. */
      // &quot;mapRoot&quot;: &quot;&quot;,                         /* Specify the location where debugger should locate map files instead of generated locations. */
      // &quot;inlineSourceMap&quot;: true,               /* Emit a single file with source maps instead of having a separate file. */
      // &quot;inlineSources&quot;: true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
  
      /* Experimental Options */
      &quot;experimentalDecorators&quot;: true,        /* Enables experimental support for ES7 decorators. */
      // &quot;emitDecoratorMetadata&quot;: true,         /* Enables experimental support for emitting type metadata for decorators. */
    },
    &quot;include&quot;: [
      &quot;components/**/*&quot;,
      &quot;pages/**/*&quot;,
    ],
    &quot;exclude&quot;: [
      &quot;node_modules&quot;,
      &quot;styles&quot;,
      &quot;_document.tsx&quot;
    ]
  }
  </code></pre>