Generics with default and $ExpectType value
malthe opened this issue · 2 comments
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?
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
Some discussion over at Typescript on the behavior of typeToString
: microsoft/TypeScript#43988.