Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract to constant refactor does not preserve type of context-sensitive function calls #40423

Open
ark120202 opened this issue Sep 8, 2020 · 0 comments
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol
Milestone

Comments

@ark120202
Copy link

TypeScript Version: 4.1.0-dev.20200907

Search Terms: isContextSensitive

Code

declare function foo<T = number>(): T;
const result: string = foo();

Apply "Extract to constant in enclosing scope" refactor on foo() expression

Expected behavior:

const newLocal: string = foo();
const result: string = newLocal;

Actual behavior:

const newLocal = foo();
const result: string = newLocal;

It doesn't seem to be intentional based on this code, and it works in this example:

const result: { x: (x: string) => string } = { x: (x) => x };
const newLocal: { x: (x: string) => string; } = { x: (x) => x };
const result: { x: (x: string) => string } = newLocal;

Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20200907#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwB4AVeAXnlWQFsAjEGAPgAoBKALnhIG4AoMHgDOGeHCHIIGLiJhZUAcwoEc7HkA

Related Issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol
Projects
None yet
2 participants