Argument of type X is not assignable to parameter of type Y?

Viewed 33

The gist of my problem is this:

type Bar = [number, number];
interface Foo {
    parameters: Array<Bar>;
}

const okay: Foo = { parameters: [[1, 2], [3, 4]] };

const x = { parameters: [[1, 2], [3, 4]] };
const notOkay: Foo = x; // error!

If I declare okay inline then it works.

However, if I do the notOkay version (which I have to do, because the JSON data is in another file, so I have to import it), then it throws an error.

The only solution seems to be to do x as Foo, but that is unfortunate because it bypasses all type-checking.

Is there a solution here which doesn't involve the as cast?

0 Answers
Related