Skip to content

Proposal: Allow isolated declarations to infer results of constructor callsΒ #60010

Open

Description

πŸ” Search Terms

isolated declarations constructor generic infer

βœ… Viability Checklist

⭐ Suggestion

Add a new flag or change the behavior of --isolatedDeclarations so that in the following code which is currently disallowed by isolated declarations:

export const foo = new Foo(a);

if the type of foo is not Foo, there is a typecheck error. In return, the type of foo will be emitted as Foo.

Similarly, if somehow in

export const foo: new Foo<A>(a);

foo is not a Foo<A>, there is a typecheck error.

πŸ“ƒ Motivating Example

Currently under isolated declarations, code must redundantly declare the type of a variable which is the result of a constructor call.

export const foo: Foo = new Foo(a);

This setting would also eliminate #59768

πŸ’» Use Cases

^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Experimentation NeededSomeone needs to try this out to see what happensSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions