Skip to content
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

Generic constraints cannot be applied to template literals #55493

Closed
missannil opened this issue Aug 24, 2023 · 2 comments
Closed

Generic constraints cannot be applied to template literals #55493

missannil opened this issue Aug 24, 2023 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@missannil
Copy link

πŸ”Ž Search Terms

Generic constraints
template literals

πŸ•— Version & Regression Information

5.1.6

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.0-beta&ssl=9&ssc=111&pln=1&pc=1#code/C4TwDgpgBMELZgDYENYBkCWsBOzEHkAjAKwgGNgoBeKAJXIHtsATAHigAMASAbwGdg2DADsA5gF8A+rwFCx4jgBpkwkAD4oAek1QmUHlADaAaygAuTjMEiJ0-tfkcAuhZUgo4gFCeyDYQJgIAQAGan1kCLMARgAmAGZxKD5UDD4AMwwgwIQUdCwIXAISckptKALsJgsAFXBoAHIDCOQLYQBXOEICgG4PeqhmBizhBkpk4FS092AAC2gIAA9ICghmGDqoetgc1AhMHDx6gDpqufLsSuwoVKhkPnKlktWoI+9QSCg0hgZWaofYYTMe7bJC7fYFPBEUgUDQ0P5vDawARRMJfH48ZrReLiDRaHRQAASDA+sxuNxU50uRygACFyMg2nxoEjgKEAO4YRCIKDYCBgJiUCkVJgIklBYAxMIYyKxBL-CCA4HwUF5A5FaGUAD8MGwbWgFjSeCZeKgt0QfAYSRmDDaiDWXU+RogigAwm0LgrgIh3DdBHqgA

πŸ’» Code

type templateLiteralObject = Record< `${string}_${string}`,any> // or { [k : `${string}_${string}`]: any }

const test0 = {aaa:123} satisfies templateLiteralObject // error: Type '{ aaa: number; }' does not satisfy the expected type 'templateLiteral'.The error is as expected .

type foo<T extends templateLiteralObject> = T 

type test1 = foo<{aaa:123}>  //  Hope this is an error. Because test0 will report an error

type test2 = {aaa:123} extends templateLiteralObject ? true : false //  also should be false,Currently is true

πŸ™ Actual behavior

test0 throw error: Type '{ aaa: number; }' does not satisfy the expected type 'templateLiteral'.

but test1 No error reported

πŸ™‚ Expected behavior

Hope test1 reported an error

Additional information about the issue

No response

@fatcerberus
Copy link

fatcerberus commented Aug 24, 2023

test0 is an excess property check error, not a type error. In general, objects can have extra properties, so you can’t constrain the set of allowed keys. See #55152.

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 24, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants