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

Generics with default and $ExpectType value #919

Open
malthe opened this issue Jan 26, 2024 · 2 comments
Open

Generics with default and $ExpectType value #919

malthe opened this issue Jan 26, 2024 · 2 comments

Comments

@malthe
Copy link

malthe commented Jan 26, 2024

Consider the following example:

class Foo<T = number> {
    public bar: T;
}

declare const foo: Foo;

// $ExpectType Foo<number>
foo;

Should this be rendered instead as just Foo – ?

There's a situation that might motivate this further than just "it's simpler" which is that perhaps generics have been added to Foo but backwards compatibility is provided through the default type.

If a type is specified using just default types, should the tool drop those types from the output?

@jakebailey
Copy link
Member

ExpectType is more or less the same as hovering, and hovering will show the instantiation. We call typeToString, and there doesn't seem to be a formatting flag that would omit type arguments when only defaults were used either.

See also twoslash queries: Playground Link

@malthe
Copy link
Author

malthe commented Jan 26, 2024

Some discussion over at Typescript on the behavior of typeToString: microsoft/TypeScript#43988.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants