小编Aml*_*lau的帖子

为什么 Typescript 映射元组类型在提供通用类型和直接类型时表现不同?

export type MyTuple = ["test", "othertest"];

type NotWorking = {
    [K in keyof MyTuple]: { value: MyTuple[K]};
};

type NotWorkingLengthType = NotWorking["length"]; // { value: 2 }

type Working<T>= {
    [P in keyof T]: { value: T[P] };
};

type MappedWorking = Working<MyTuple>;
type MappedWorkingLengthType = MappedWorking["length"]; // 2
Run Code Online (Sandbox Code Playgroud)

为什么在这种情况下它的行为有所不同?这让我很困惑。

tuples typescript

5
推荐指数
1
解决办法
1469
查看次数

标签 统计

tuples ×1

typescript ×1