🔎 Search Terms
generic, type, class, and, &, or, |, combined
⏯ Playground Link
Playground
💻 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 |
🔎 Search Terms
generic, type, class, and, &, or, |, combined
⏯ Playground Link
Playground
💻 Code
🙁 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
|