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
type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1 = First<arr1> // expected to be 'a' type head2 = First<arr2> // expected to be 3
就是实现一个 First 将数组中的第一个元素取出来成为新的类型
First
type First<T extends any[]> = T extends [] ? never : T[0]
这里利用了 extends 的条件判断,extends 在 interface 中作为继承,在type中可以作为条件判断,这里就类似于js中的三元运算
extends
interface
type
js
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题
就是实现一个
First
将数组中的第一个元素取出来成为新的类型答案
讲解
这里利用了
extends
的条件判断,extends
在interface
中作为继承,在type
中可以作为条件判断,这里就类似于js
中的三元运算The text was updated successfully, but these errors were encountered: