Skip to content

Generic constraints cannot be applied to template literalsΒ #55493

Closed as not planned
@missannil

Description

@missannil

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions