GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Support completions contextual types in more places · Pull Request #20768 · microsoft/TypeScript Conversation
|
| // the contextual type of an initializer expression is the type annotation of the containing declaration, if present. | ||
| function getContextualTypeForInitializerExpression(node: Expression): Type { | ||
| const declaration = <VariableLikeDeclaration>node.parent; | ||
| if (hasInitializer(declaration) && node === declaration.initializer || node.kind === SyntaxKind.EqualsToken) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why does = go away? I guess that it's because in batch compilation, = doesn't have a type, and node is in fact only ever = when called from services.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Right, this code was added in #20020 and this PR moves the special cases to completions.ts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| case SyntaxKind.ExclamationEqualsEqualsToken: | ||
| case SyntaxKind.ExclamationEqualsToken: | ||
| // For completions after `x === ` | ||
| return node === operatorToken ? getTypeOfExpression(binaryExpression.left) : undefined; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
is this really not used anywhere else besides services?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, this was also added by #20020.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| case ts.SyntaxKind.EqualsToken: | ||
| return ts.isVariableDeclaration(parent) | ||
| ? checker.getContextualType(parent.initializer) | ||
| : ts.isBinaryExpression(parent) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
can you reformat like so?
return ts.isVariableDeclaration(parent) ? checker.getContextualType(parent.initializer) : ts.isBinaryExpression(parent) ? checker.getTypeAtLocation(parent.left) : undefined;
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.