We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is 指定推导结果类型:
is
filter<S> S 可以忽略不填,但是返回值 value is S 必须手写
filter<S>
value is S
type Alice = { name: string; department: string; } type Bob = { name: string; department: boolean; } type Carl = { name: string; department: number; } type AllName = Alice | Bob | Carl; const employees: AllName[] = [ { name: 'Alice', department: 'accounting' }, { name: 'Bob', department: true }, { name: 'Carl', department: 10 }, ]; const isAlice = (obj: AllName): obj is Alice => obj.name === 'Alice'; const result = employees.filter(isAlice); // result => Alice[];
The text was updated successfully, but these errors were encountered:
No branches or pull requests
array filter 泛型返回具体元素类型
is
指定推导结果类型:filter<S>
S 可以忽略不填,但是返回值value is S
必须手写The text was updated successfully, but these errors were encountered: