TypeScriptでsomeを使った絞り込みの処理をしようとしていますが、
エラーが発生し、解決方法がわかりません。
また、学び始めたばかりなので書き方が違うなどのご指摘もあれば
ご教示頂ければと思います。
エラー内容
bash
1Argument of type '(key: string) => true | undefined' is not assignable to parameter of type '(value: string, index: number, array: string[]) => boolean'. 2 Type 'true | undefined' is not assignable to type 'boolean'. 3 Type 'undefined' is not assignable to type 'boolean'.
ソース
ts
1import { Component, Vue, Prop } from 'vue-property-decorator' 2@Component 3export default class AdminList extends Vue { 4 // props 5 @Prop({ type: Array, required: true }) 6 companies!: {key: string}[] 7 @Prop({ type: Array, required: true }) 8 sortBar!: string[] 9 // data 10 list: {key: string}[] = this.companies 11 searchWord: string = '' 12 selectCategory: string = '' 13 count: number = 10 14 sort = { key: '', isAsc: false } 15 formError: string = '' 16 17 // computed 18 get sortedItems() { 19 let list: any = this.list 20 const filterWord = this.searchWord 21 if (this.sort.key) { 22 list.sort((a, b) => { 23 a = a[this.sort.key] 24 b = b[this.sort.key] 25 return (a === b ? 0 : a > b ? 1 : -1) * (this.sort.isAsc ? 1 : -1) 26 }) 27 } 28 if (filterWord) { 29 list = list.filter(function (row) { 30 if (filterWord) { 31 return Object.keys(row).some(function (key) { 32 if (String(row[key]).toLowerCase().indexOf(filterWord) > -1) { 33 return true 34 } 35 }) 36 } 37 return row 38 }) 39 } 40 return list.slice(0, this.count) 41 } 42}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/31 05:32