Is there any difference between the parameter transfer type of the ts generic function and the internal definition type of the generic function?
I know that keyof can generate string or numeric literal union of its key for object type
type Data = { a: string, b: number } keyof Data;// 'a' | 'b'
But if I apply it to literal types, I will get union types similar to all its attributestype Test = keyof 'a';
// result
type Test = number | typeof Symbol.iterator | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | ... 30 more ... | "padEnd"
I know that the "in" operator in typescript can be used to traverse the attribute names of the target type
type Test = {
[P in keyof 'a']: '??'
};
type T = Test;
// result
type T = {
[x: number]: "??";
toString: "??";
charAt: "??";
charCodeAt: "??";
concat: "??";
indexOf: "??";
lastIndexOf: "??";
localeCompare: "??";
match: "??";
replace: "??";
search: "??";
slice: "??";
split: "??";
... 30 more ...;
[Symbol.iterator]: "??";
}
But I don't understand why the results are completely different once they are passed in through generics
type Test<V> = {
[P in keyof V]: '??'
};
type T = Test<'a'>;
// result
type T = 'a'