[TS] Issue on example with Array
See original GitHub issueI just copied this example :
// What we have
interface Source {
ugly_field: string;
}
// What we want
interface Destination {
field: string;
}
const source: Source = {
ugly_field: 'field value'
};
// Destination and Source types are optional
morphism<Destination, Source>({ field: 'ugly_field' }, source);
// => {field: "field value"}
// Or
const sources = [source];
const schema: StrictSchema<Destination, Source> = { field: 'ugly_field' };
morphism<Destination, Source>(schema, sources);
// => [{field: "field value"}]
And I got the following error when applying morphism which is suppose to return an array :
Argument of type 'StrictSchema<Destination, Source>' is not assignable to parameter of type 'Destination'.
Types of property 'field' are incompatible.
Type 'string | string[] | ActionFunction<Destination, Source, string> | "ugly_field"[] | ActionSelector<Source, string>' is not assignable to type 'string'.
Type 'string[]' is not assignable to type 'string'.ts(2345)
Any tips on how to solve this problem ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
TS ^4 does not recognize array methods on (T[] | T[][]) as callable
The error disappears if the array is initialized with something inside. const a: string[] | string[] ...
Read more >TypeScript Arrays - GeeksforGeeks
An array is a user-defined data type. An array is a homogeneous collection of similar types of elements that have a contiguous memory ......
Read more >Defining array with multiple types in TypeScript - Stack Overflow
This won't work with complex types with different properties, when you want to access a property available on only one of the types....
Read more >Array.prototype.some() - JavaScript - MDN Web Docs - Mozilla
The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true...
Read more >Practical Guide to Fp-ts P4: Arrays, Semigroups, Monoids
Now we must answer the question: how do we go from Array<A> NonEmptyArray<A> . In our example, we can do this by replacing...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Everything is alright with latest release 1.11.0 ! Closing this issue 😃
I knew there was something wrong with TS ! My typescript version is
3.1.3
, I will try with the latest version on Monday and keep you updated.Workaround is working as expected, great lib and great support 😃