Skip to content

关于 21章节 第4小节 extends... ? : 的疑问,貌似有问题 #125

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

Closed
coderwhytop opened this issue Oct 15, 2024 · 1 comment
Closed

Comments

@coderwhytop
Copy link

f6d44b22a90ddf0f915beff31fd5656
你好,按照这里说的,type Z = ('x' | 1) extends (string | boolean) ? 'x' : 1; 分解为 ('x' extends string | boolean ? 'x' : 1) | (1 extends string | boolean ? 'x' : 1), 岂不是 返回 'x' | 1 了 ?

@ruanyf ruanyf closed this as completed in 1725cbb Oct 15, 2024
@ruanyf
Copy link
Contributor

ruanyf commented Oct 15, 2024

谢谢指出,已经更正。

正确说法是这个只对泛型有效。

type T1 = 'x' | 1;
type T2<T> = T extends (string | boolean) ? 'x' : 1;
type T3 = T2<T1>; // 'x' | 1

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

2 participants