question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TS] Issue on example with Array

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Sangrenecommented, May 13, 2019

Everything is alright with latest release 1.11.0 ! Closing this issue 😃

1reaction
Sangrenecommented, May 10, 2019

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found