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 {
42198
42198
if (isDeclaration(node)) {
42199
42199
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
42200
42200
const symbol = getSymbolOfNode(node);
42201
- return getTypeOfSymbol(symbol);
42201
+ return symbol ? getTypeOfSymbol(symbol) : errorType ;
42202
42202
}
42203
42203
42204
42204
if (isDeclarationNameOrImportPropertyName(node)) {
Original file line number Diff line number Diff line change @@ -130,6 +130,26 @@ describe("unittests:: Public APIs:: getTypeAtLocation", () => {
130
130
const type = checker . getTypeAtLocation ( file ) ;
131
131
assert . equal ( type . flags , ts . TypeFlags . Any ) ;
132
132
} ) ;
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
+ } ) ;
133
153
} ) ;
134
154
135
155
describe ( "unittests:: Public APIs:: validateLocaleAndSetLanguage" , ( ) => {
You can’t perform that action at this time.
0 commit comments