Closed
Description
π Search Terms
generic, type, class, and, &, or, |, combined
β― Playground Link
π» Code
class ExampleClass<T>
{
test(value: T): T
{
return value;
}
}
class Example1 extends ExampleClass<String> { }
class Example2 extends ExampleClass<Number> { }
function Example(example: 1|2) // returns `typeof Example1 | typeof Example2`
{
return example===1?Example1:Example2;
}
const instance = new (Example(1))();
instance.test(''); // ERROR: Argument of type 'string' is not assignable to parameter of type 'Number & String'
π Actual behavior
Combining classes with generic type results in generic types on arguments to be combined with &
.
But get combined with |
for return types.
π Expected behavior
Expected the types to be combined with |
Metadata
Metadata
Assignees
Labels
No labels