-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
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
Class implementation ignores optionality of method parameter in interface #27523
Comments
Things declared with method syntax are subject to parameter bivariance (see FAQ) due to the prevalence of (yes, unsound) class hierarchies in the wild that float their parameter types in the "wrong" direction |
@RyanCavanaugh I'm assuming this is equivalent to the following example?
I'm trying to find a way to validate these signatures at compile time. The implementation in my example has a bug; it should have been declared with the parameter |
@sharwell correct. Unfortunately there's not a way to enable strict checks here (doing so would be trivial from an implementation perspective, but would immediately create errors in the DOM lib) |
The issue is not reported by the compiler. See microsoft/TypeScript#27523.
The issue is not reported by the compiler. See microsoft/TypeScript#27523.
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.2.0-dev.201xxxxx
Search Terms: interface, optional parameter
Code
Expected behavior:
Compilation error once strictNullChecks like TS2416: Type '(s: string) => void' is not assignable to type '(s?: string | undefined) => void'.
Actual behavior:
No compilation errors.
Playground Link
The text was updated successfully, but these errors were encountered: