Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
@ark120202

Description

@ark120202

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbol

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions