Skip to content

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

Closed
@coderwhytop

Description

@coderwhytop

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

Activity

ruanyf

ruanyf commented on Oct 15, 2024

@ruanyf
Contributor

谢谢指出,已经更正。

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

type T1 = 'x' | 1;
type T2<T> = T extends (string | boolean) ? 'x' : 1;
type T3 = T2<T1>; // 'x' | 1
added a commit that references this issue on Oct 16, 2024
1725cbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ruanyf@coderwhytop

        Issue actions

          关于 21章节 第4小节 extends... ? : 的疑问,貌似有问题 · Issue #125 · wangdoc/typescript-tutorial