-
Notifications
You must be signed in to change notification settings - Fork 12.8k
polymorphic arguments validation error #20268
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
Comments
currently blocks wix-incubator/wix-react-tools#188 |
Seems to have been caused by #17806. a possible solution here is to add an overload for |
@mhegazy thanks for the workaround |
This error appears to have to do with type Processor<T extends object> = <T1 extends T>(subj: T1) => T1
function doStuff<T extends object, T1 extends T>(parentProcessors: Array<Processor<T>>, childProcessors : Array<Processor<T1>>) {
const x: ReadonlyArray<Processor<T1>> = parentProcessors; // This is an error...
const foo: Processor<T1> = parentProcessors[0]; // But this does work?
childProcessors.concat(x);
}
If we remove |
This actually isn't a bug. But it is complicated. First, imagine that type Processor<T extends object> = (subj: T) => T; This function is invariant for Now, changing type Processor<T extends object> = <T1 extends T>(subj: T1) => T1; This shouldn't really change matters. The function is still invariant for My conclusion is that the error in the original example is correct, and that the "fix" in #20455 isn't actually a fix, but rather a change that causes us to not error when we still should. I think the correct course of action is to reverse #20455 and leave things the way they were. |
I was right that it is complicated. But I was wrong about it not being a bug. It is. The original The actual issue is a combination of two changes: #15104 (covariant checking for callback parameters) and #17806 (arguments to It is actually correct that there is an error. What's wrong is the way |
TypeScript Version: 2.7.0-dev.20171126
(Introduced in 2.6)
Code
Expected behavior:
pass validation (polymorphism etc.)
Actual behavior:
Error:(3, 28) TS2345:Argument of type 'Processor[]' is not assignable to parameter of type 'Processor | ReadonlyArray<Processor>'.
Type 'Processor[]' is not assignable to type 'ReadonlyArray<Processor>'.
Types of property 'indexOf' are incompatible.
Type '(searchElement: Processor, fromIndex?: number | undefined) => number' is not assignable to type '(searchElement: Processor, fromIndex?: number | undefined) => number'.
Types of parameters 'searchElement' and 'searchElement' are incompatible.
Types of parameters 'subj' and 'subj' are incompatible.
Type 'T1' is not assignable to type 'T1'. Two different types with this name exist, but they are unrelated.
Type 'T' is not assignable to type 'T1'.
Type 'object' is not assignable to type 'T1'.
The text was updated successfully, but these errors were encountered: