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
因为t并不等于User,t是User的子类,所以t可能会有更多的属性,而这只是返回了User,可以这样修改👇
type User = { id: number; kind: string; }; function makeCustomer<T extends User>(u: T):User { return { id: u.id, kind: 'customer' } } function makeCustomer<T extends User>(u: T):T { return { ...u,// 这里u拥有T的全部属性,返回T的扩展也是可以的 id: u.id, kind: 'customer' } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
因为t并不等于User,t是User的子类,所以t可能会有更多的属性,而这只是返回了User,可以这样修改👇
The text was updated successfully, but these errors were encountered: