We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeScript Version: 3.9.2 (also tested in nightly)
Search Terms: TS2416 literal subclass methods literals
Code
class foo { fn(x: string) { return x; } } class bar extends foo { fn(x: 'a' | 'b' | 'c') { return ''; } } class baz extends foo { fn(x: 'a' | 'b' | 'c' | undefined) { return ''; } }
Expected behavior:
Getting an error Property 'fn' in type <sub class> is not assignable to the same property in base type 'foo'. As
Property 'fn' in type <sub class> is not assignable to the same property in base type 'foo'.
Types of parameters 'x' and 'x' are incompatible. Type 'string' is not assignable to type <corresponding param type of fn in sub class>.
for both classes bar and baz
Actual behavior:
The error is only shown on class baz. It should also be there on bar as string is not assignable to 'a' | 'b' | 'c' also.
baz
bar
string
'a' | 'b' | 'c'
Playground Link: playground
Related Issues: couldn't find (#35151 came up in search and looked similar but it was a different issue.)
The text was updated successfully, but these errors were encountered:
Class method types are compared bivariantly; see comments in #18654
Sorry, something went wrong.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
TypeScript Version: 3.9.2 (also tested in nightly)
Search Terms:
TS2416 literal
subclass methods literals
Code
Expected behavior:
Getting an error
Property 'fn' in type <sub class> is not assignable to the same property in base type 'foo'.
As
for both classes bar and baz
Actual behavior:
The error is only shown on class
baz
. It should also be there onbar
asstring
is not assignable to'a' | 'b' | 'c'
also.Playground Link: playground
Related Issues: couldn't find (#35151 came up in search and looked similar but it was a different issue.)
The text was updated successfully, but these errors were encountered: