Skip to content
New issue

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

what is the diffrence between <T> and <T, _> #502

Open
luckydog12 opened this issue Feb 7, 2022 · 3 comments
Open

what is the diffrence between <T> and <T, _> #502

luckydog12 opened this issue Feb 7, 2022 · 3 comments

Comments

@luckydog12
Copy link

i can't understand

@elkarouani
Copy link
Contributor

Hi @luckydog12, you can identify an example so your question can be answered precisely !

@luckydog12
Copy link
Author

luckydog12 commented Feb 8, 2022

const clone = <T, _>(arr: T[]): T[] => [...arr]
i try to ignore _ , use < T > like this: const clone = < T > (arr: T[]):T[] => [...arr]
it also work, so i don't know _ for what?????
can u understand what i mean ?

@sunmaobin
Copy link

sunmaobin commented Jun 9, 2022

@luckydog12 <T, _> 相当于是2个参数类型的泛型约束,就像 <T, U> 写法一样,只是这里第二个参数类型约束没用上,因为你的示例代码只有一个参数,如果把你的示例改改,可能就好理解了。
比如:const clone = <T, _>(arr:T[], arr2:_[]):(T|_)[] => [...arr, ...arr2]
等同于:const clone = <T, U>(arr:T[], arr2:U[]):(T|U)[] => [...arr, ...arr2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants