File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -42198,7 +42198,7 @@ namespace ts {
4219842198 if (isDeclaration(node)) {
4219942199 // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
4220042200 const symbol = getSymbolOfNode(node);
42201- return getTypeOfSymbol(symbol);
42201+ return symbol ? getTypeOfSymbol(symbol) : errorType ;
4220242202 }
4220342203
4220442204 if (isDeclarationNameOrImportPropertyName(node)) {
Original file line number Diff line number Diff line change @@ -130,6 +130,26 @@ describe("unittests:: Public APIs:: getTypeAtLocation", () => {
130130 const type = checker . getTypeAtLocation ( file ) ;
131131 assert . equal ( type . flags , ts . TypeFlags . Any ) ;
132132 } ) ;
133+
134+ it ( "returns an errorType for VariableDeclaration with BindingPattern name" , ( ) => {
135+ const content = "const foo = [1];\n" + "const [a] = foo;" ;
136+
137+ const host = new fakes . CompilerHost ( vfs . createFromFileSystem (
138+ Harness . IO ,
139+ /*ignoreCase*/ true ,
140+ { documents : [ new documents . TextDocument ( "/file.ts" , content ) ] , cwd : "/" } ) ) ;
141+
142+ const program = ts . createProgram ( {
143+ host,
144+ rootNames : [ "/file.ts" ] ,
145+ options : { noLib : true }
146+ } ) ;
147+
148+ const checker = program . getTypeChecker ( ) ;
149+ const file = program . getSourceFile ( "/file.ts" ) ! ;
150+ const [ declaration ] = ( ts . findLast ( file . statements , ts . isVariableStatement ) as ts . VariableStatement ) . declarationList . declarations ;
151+ assert . equal ( checker . getTypeAtLocation ( declaration ) . flags , ts . TypeFlags . Any ) ;
152+ } ) ;
133153} ) ;
134154
135155describe ( "unittests:: Public APIs:: validateLocaleAndSetLanguage" , ( ) => {
You can’t perform that action at this time.
0 commit comments