B
B
become_iron2017-10-11 01:43:34
JavaScript
become_iron, 2017-10-11 01:43:34

How to resolve signature mismatch when using third party libraries?

I create some interface:

export interface Syllable {
  readonly id: number;
  readonly hiragana?: string;
  readonly katakana: string;
  readonly transcription: string;
}

I then write an abstract class and declare a method in it that returns Syllable[]. I inherit from this class, in the body of the method definition I use a function from another library:
// underscore.js
return _.shuffle(this.proposed_options);

As a result, it turns out that the signatures do not match: I return not Syllable[], but {}[].
Therefore, I bring it manually to the desired signature:
// underscore.js
<Syllable[]>_.shuffle(this.proposed_options)

The question is how to properly deal with this situation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Drapeza, 2017-10-11
@become_iron

Shuffle method declaration:
The this.proposed_options class property may not be typed as Syllable.
Rewrite manually but using generic:
_.shuffle<Syllable>(this.proposed_options)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question