-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inconsistent 'keyof' keyword in Record type and Object literal type #49540
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
Comments
The case |
but I can't understand how |
These are different syntaxes for different things. https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#handbook-content & https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures |
type A = { [x: string] : unknown}
type B = Record<string, unknown>;
const a: A = { 0: "test", a: "test" };
const b: B = { 0: "test", b: "test" };
function testA<T extends A>(a: T) {
return a;
}
function testB<T extends B>(b: T) {
return b;
}
testA(a);
testA(b);
testB(a);
testB(b); It absolutely works same. but using 'keyof' is difference. is it intended? but why? |
Because these are different features with different purposes. With The two having different |
I didn't understand clearly but I got to understand it is different features. Thank you for reply! |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
π Version & Regression Information
testing in 4.7.3. but it occured every version.
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
keyof A is string.
keyof B is string | number
keyof C is string.
π Expected behavior
Every keyof A, B, C types should be string | number OR string.
https://www.typescriptlang.org/docs/handbook/2/keyof-types.html
Honestly, I don't know what is difference using 'in' keyword at key of this code. but it makes different result so I post this issue.
The text was updated successfully, but these errors were encountered: