Merge pull request #28071 from pesca/improveCodeFix

Improve code fix for missing members
This commit is contained in:
Daniel Rosenwasser
2018-11-06 11:29:51 -08:00
committed by GitHub
4 changed files with 33 additions and 1 deletions
@@ -185,6 +185,10 @@ namespace ts.codefix {
const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
typeNode = checker.typeToTypeNode(widenedType, classDeclaration);
}
else {
const contextualType = checker.getContextualType(token.parent as Expression);
typeNode = contextualType ? checker.typeToTypeNode(contextualType) : undefined;
}
return typeNode || createKeywordTypeNode(SyntaxKind.AnyKeyword);
}
@@ -0,0 +1,14 @@
/// <reference path='fourslash.ts' />
//// class C {}
//// const x: number = new C().x;
verify.codeFix({
description: "Declare property 'x'",
index: 0,
newFileContent:
`class C {
x: number;
}
const x: number = new C().x;`
});
@@ -0,0 +1,14 @@
/// <reference path='fourslash.ts' />
//// class C {}
//// const x: number = new C().x;
verify.codeFix({
description: "Add index signature for property 'x'",
index: 1,
newFileContent:
`class C {
[x: string]: number;
}
const x: number = new C().x;`
});
@@ -19,7 +19,7 @@ verify.codeFix({
index: 0,
newFileContent:
`interface I {
bar: any;
bar: number;
}
function f<T>(t: T): number {