Merge pull request #18424 from amcasey/ExtractTypeParameter

Stop preventing extraction when a type parameter wouldn't bind correctly in a containing scope
This commit is contained in:
Andrew Casey 2017-09-13 16:42:42 -07:00 committed by GitHub
commit 7b64229f65
3 changed files with 29 additions and 1 deletions

View File

@ -728,6 +728,11 @@ function parseUnaryExpression(operator: string): UnaryExpression {
function parsePrimaryExpression(): any {
throw "Not implemented";
}`);
// Type parameter as declared type
testExtractMethod("extractMethod30",
`function F<T>() {
[#|let t: T;|]
}`);
});

View File

@ -1222,7 +1222,11 @@ namespace ts.refactor.extractMethod {
substitutionsPerScope[i].set(symbolId, substitution);
}
else if (isTypeName) {
errorsPerScope[i].push(createDiagnosticForNode(identifier, Messages.TypeWillNotBeVisibleInTheNewScope));
// If the symbol is a type parameter that won't be in scope, we'll pass it as a type argument
// so there's no problem.
if (!(symbol.flags & SymbolFlags.TypeParameter)) {
errorsPerScope[i].push(createDiagnosticForNode(identifier, Messages.TypeWillNotBeVisibleInTheNewScope));
}
}
else {
usagesPerScope[i].usages.set(identifier.text as string, { usage, symbol, node: identifier });

View File

@ -0,0 +1,19 @@
// ==ORIGINAL==
function F<T>() {
let t: T;
}
// ==SCOPE::inner function in function 'F'==
function F<T>() {
/*RENAME*/newFunction();
function newFunction() {
let t: T;
}
}
// ==SCOPE::function in global scope==
function F<T>() {
/*RENAME*/newFunction<T>();
}
function newFunction<T>() {
let t: T;
}