mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
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:
commit
7b64229f65
@ -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;|]
|
||||
}`);
|
||||
});
|
||||
|
||||
|
||||
@ -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 });
|
||||
|
||||
19
tests/baselines/reference/extractMethod/extractMethod30.ts
Normal file
19
tests/baselines/reference/extractMethod/extractMethod30.ts
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user