【发布时间】:2020-04-23 01:53:53
【问题描述】:
我正在遵循这些说明:“返回所提供数组中所有知道打字稿的人的数组”
export interface Person {
name: string,
netWorth: number,
coder?: boolean,
us?: boolean
city: string,
languages: string[]
}
export const cities = ['nyc', 'sf', 'la']
export const languages = [
'javascript',
'typescript',
'html',
'css',
'c#',
'python',
'ruby',
]
我认为它会很简单:
export function allCodersWhoKnowTypescript(people: Person[]): Person[] {
people = people.filter(languages => languages === ('typescript'))
return people
}
但我得到了错误:
This condition will always return `false` since the types `Person` and `string` have no overlap.
【问题讨论】:
-
请提及您使用的编程语言。将该编程语言放在标签和标题中将有助于引起人们对您的关注。
标签: arrays typescript arraylist methods filtering