Closed
Description
TypeScript Version: 3.2.2
Search Terms:
error TS2322: Types of property 'length' are incompatible. Type '2' is not assignable to type '1'.
Code
type ProxyComponent {
simulate() {
//Some Implementation
}
}
type UserStory = {
setup: () => [(component: ProxyComponent) => void]
};
//Compiles perfectly!
let userStory: UserStory = {
setup: () => [(component) => component.simulate()]
}
//Fails to Compile!
/*
error TS2322: Type '[(component: ProxyComponent) => void, (component: ProxyComponent) => void]' is not assignable to type '[(component: ProxyComponent) => void]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
*/
let userStory1: UserStory = {
setup: () => [(component) => component.simulate(), (component) => component.simulate()]
}
I tried multiple things:
- Creating a Type for the closure and using it as the type of the setup property but that gives the same error. like
type SetupStatement = () => [(component: ProxyComponent) => void];
but that didn't work either. - Declaring the value of the setup method.
Expected behavior:
Code should compile correctly because the return types of the array match. It works perfectly for a single element but fails for multiple elements.
Actual behavior:
Compilation fails with the following error
error TS2322: Type '[(component: ProxyComponent) => void, (component: ProxyComponent) => void]' is not assignable to type '[(component: ProxyComponent) => void]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
Playground Link:
Link to Playground
Related Issues:
Metadata
Metadata
Assignees
Labels
No labels