autocomplete works for const assertion. (#39412)

* fix 39384

* add test
This commit is contained in:
ShuiRuTian 2020-07-06 20:49:50 +08:00 committed by GitHub
parent 9a5c0074aa
commit f29e03eea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -23425,7 +23425,7 @@ namespace ts {
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
case SyntaxKind.TypeAssertionExpression:
case SyntaxKind.AsExpression:
return isConstTypeReference((<AssertionExpression>parent).type) ? undefined : getTypeFromTypeNode((<AssertionExpression>parent).type);
return isConstTypeReference((<AssertionExpression>parent).type) ? tryFindWhenConstTypeReference(<AssertionExpression>parent) : getTypeFromTypeNode((<AssertionExpression>parent).type);
case SyntaxKind.BinaryExpression:
return getContextualTypeForBinaryOperand(node, contextFlags);
case SyntaxKind.PropertyAssignment:
@ -23458,6 +23458,13 @@ namespace ts {
return getContextualJsxElementAttributesType(<JsxOpeningLikeElement>parent, contextFlags);
}
return undefined;
function tryFindWhenConstTypeReference(node: Expression) {
if(isCallLikeExpression(node.parent)){
return getContextualTypeForArgument(node.parent, node);
}
return undefined;
}
}
function getInferenceContext(node: Node) {

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
////type T = {
//// a: 1;
//// b: 2;
////}
////function F(x: T) {
////}
////F({/*1*/} as const)
verify.completions({
marker: "1",
exact: [
{ name: "a", text: "(property) a: 1" },
{ name: "b", text: "(property) b: 2" },
],
});