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
The --strictNullChecks PR changed some declarations in types.ts to avoid frequent assertions in the compiler's code. Unfortunately these changes make it really unsafe for API users because they no longer contain the actually nullable types: #22088 (comment)#22088 (comment)
ts.Node#parent is no longer optional (which is definitely wrong for SourceFile)
ts.Symbol#declarations and ts.Symbol.valueDeclaration are no longer optional, but can still be undefined
ts.Type#symbol is no longer optional, but I guess this comment is still up to date: // Symbol associated with type (if any)
Ryan Cavanaugh (@RyanCavanaugh) Do you plan to fix this in the near future? It's a real PITA for me as I use TypeScript's API a lot.
Is there anything I can do to help? Would you accept PRs to fix the issues listed above (probably one at a time to keep the diff small)?
// analyze.jsconstts=require('typescript');constprogram=ts.createProgram(['src/index.ts'],{target: ts.ScriptTarget.ES2015,noEmit: true,strict: true});constchecker=program.getTypeChecker();// get the fileconst[indexFile]=program.getSourceFiles().filter(f=>!f.isDeclarationFile);// file's symbolconstindexFileSymbol=checker.getSymbolAtLocation(indexFile);// file's exportsconst{exports: exportSymbols}=indexFileSymbol;// first exported symbol from the fileconstfirstExport=exportSymbols.values().next().value;console.log('First symbol has type of',checker.typeToString(checker.getDeclaredTypeOfSymbol(firstExport)),'and it has a valueDeclaration of',firstExport.valueDeclaration);
Result: of node analyze.js
First symbol has type of NumberDict and it has a valueDeclaration of undefined
We just ran into this bug in @typescript-eslint. One of our rules assumed the typing was correct, causing a bug for an end user.
As an API consumer, we rely on the types to help us ensure we catch bugs at compile time, and it's counter-intuitive to handle cases that are contrary to the types.
Activity
weswigham commentedon Jun 5, 2018
I agree. I mentioned it on the PR. Now that we've done the bulk of the changes, we should fix one at a time and introduce helpers to help the pain.
ajafff commentedon Sep 17, 2018
Ryan Cavanaugh (@RyanCavanaugh) Do you plan to fix this in the near future? It's a real PITA for me as I use TypeScript's API a lot.
Is there anything I can do to help? Would you accept PRs to fix the issues listed above (probably one at a time to keep the diff small)?
mike-north commentedon Jan 17, 2019
repro case for
ts.Symbol.valueDeclarationbeing undefinedResult: of
node analyze.jsbradzacher commentedon May 7, 2019
We just ran into this bug in
@typescript-eslint. One of our rules assumed the typing was correct, causing a bug for an end user.As an API consumer, we rely on the types to help us ensure we catch bugs at compile time, and it's counter-intuitive to handle cases that are contrary to the types.
Related issues:
typescript-eslint/typescript-eslint#498
typescript-eslint/typescript-eslint#496
fix(typescript_indexer): perform non-null check on symbol values
ayazhafiz commentedon Aug 19, 2019
Wesley Wigham (@weswigham) Ryan Cavanaugh (@RyanCavanaugh) will you accept changes fixing this?
fix(core): undecorated-classes-with-decorated-fields migration should…
Make `Symbol#valueDeclaration` optional in public API
fix(core): undecorated-classes-with-decorated-fields migration should…
fix(core): undecorated-classes-with-decorated-fields migration should…
feat(eslint-plugin-internal): add rule no-poorly-typed-ts-props
feat(eslint-plugin-internal): add rule no-poorly-typed-ts-props