error TS2339: Property 'x' does not exist on type 'Y'

前端 未结 6 1209
忘掉有多难
忘掉有多难 2020-12-01 12:02

I don\'t understand why this code generates TypeScript error. (It\'s not the original code and is a bit derived, so please ignore the non-sense in the example):



        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 12:32

    The correct fix is to add the property in the type definition as explained by @Nitzan Tomer. But also you can just define property as any, if you want to write code almost as in JavaScript:

    arr.filter((item:any) => {
        return item.isSelected == true;
    }
    

提交回复
热议问题