-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
With class Foo<in out T = any>, TS correctly decides that Foo<string> doesn't extend Foo<string | number>. And yet, it incorrectly decides that class StringFoo extends Foo<string> extends Foo<string | number>.
🔎 Search Terms
invariant in out type parameter annotation subclass
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "invariant", "bivariant", "in out", and "variance"
⏯ Playground Link
💻 Code
export abstract class Foo<in out T = any> {
abstract _parse(input: unknown): T;
}
export class StringFoo extends Foo<string> {
_parse(input: unknown): string {
return String(input);
}
}
// @ts-expect-error
const a: Foo<string | number> = null as any as Foo<string>
// @ts-expect-error ❌
const b: Foo<string | number> = null as any as StringFoo🙁 Actual behavior
TypeScript thinks StringFoo extends Foo<string | number>.
🙂 Expected behavior
If Foo<string> doesn't extend type X, then class StringFoo extends Foo<string> shouldn't either.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug