TransWikia.com

Type 'number' is not assignable to type 'never'. using fill array?

Stack Overflow Asked on December 13, 2021

interface Itype { 
    type: number;
    name?: string;
}    

function makeEqualArrays(arr1: Itype[], arr2: Itype[]): void { 
      arr2 = arr2.concat([].fill({ type: 2 }, len1 - len2));
}

Why I can not fill array by object?

Type ‘number’ is not assignable to type ‘never’.

One Answer

You have to type the new array you are creating [] like :

([] as Itype[])

playground

interface Itype { 
    type: number;
    name?: string;
}    

function makeEqualArrays(arr1: Itype[], arr2: Itype[]): void { 
    arr2 = arr2.concat(([] as Itype[]).fill({
        type: 2,name
    }, 5));
}

Answered by Orelsanpls on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP