You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//@target: esnext//@moduleResolution: node//@module: commonjsdeclarevarprocess: any;declarevarConsole: any;(()=>{constarg: string=process.argv[2]!;constarr: string[]=process.argv;letinfo: string|undefined=undefined;info=arg;if(info===undefined){console.log([]);return;}console.log(arr.find((e)=>e===info));// No errorconsole.log(arr.find((e)=>e.length===info.length));// Error: TS2532: Object is possibly undefinedconsole.log(info);// No error (This is correct)console.log(info.length);// No error})();
Output
"use strict";(()=>{constarg=process.argv[2];constarr=process.argv;letinfo=undefined;info=arg;if(info===undefined){console.log([]);return;}console.log(arr.find((e)=>e===info));// No errorconsole.log(arr.find((e)=>e.length===info.length));// Error: TS2532: Object is possibly undefinedconsole.log(info);// No error (This is correct)console.log(info.length);// No error})();
Unable to compile TypeScript and compiler says "'info' is undefied".
if my code is wrong, I should get same error at line 18 and 21, but I didn't get that error.
π Expected behavior
"info" is not undefined because already returned, so it should be compiled.
I don't know that cause.
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
TS2532, possibly undefined
π Version & Regression Information
typescript@4.6.2
@types/node@17.0.33
Node.js v16.14.2
npm v8.1.2
β― Playground Link
Playground link with relevant code
π» Code
Output
Compiler Options
Playground Link: Provided
π Actual behavior
Unable to compile TypeScript and compiler says "'info' is undefied".
if my code is wrong, I should get same error at line 18 and 21, but I didn't get that error.
π Expected behavior
"info" is not undefined because already returned, so it should be compiled.
I don't know that cause.
The text was updated successfully, but these errors were encountered: