🔎 Search Terms
mapped type template literal
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about current version
⏯ Playground Link
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoE8AOECydPIDeAUMsnAFzIDkAgtacgEZXUBCDAvscQCYQIANnCgoEAexABnMMhhUAPKmQQAHpBC8pNONWQAfGk2oA+ABSqqAAwAkhVJysBKZAF4TaLLnwBtVAF0eMC9kADEARjdkJRV1CE1tal0DI1MLazsHZzcPDGw8TD9AiWlZGHCqCKiYZAB6WuQAdwALdGRecQhtMGbgbWgocSgAfiCQ0IAmKJi1DS0dPUNqY3NLZFt7Rxd3T3zfDaz-Ooa4TSbW9s7tAFs4AGtQAHNkHpRRMABXKBAXkLgXiDXTDCSDIQTASBQOCCOTAVTICGjEoyOQTSpTVxyIA
💻 Code
The unexpected error is marked by a comment in the code bellow. A second comment highlights a case, where this issue does not occur, even though the two cases should be identical, as far as i understand. Thank you Matt Kantor (@mkantor) for the minimalistic example. The issue has been discussed on the TS discord in various channels. The original discussion was an "ask for help" here - https://discord.com/channels/508357248330760243/1139519033809575966/1139519033809575966
interfaceTypeMap{a: 'A'b: 'B'}declareconstf: <Textends'a'|'b'>(x: `${T}`)=>TypeMap[T]typeF1=<Textends'a'|'b'>(x: `${T}`)=>TypeMap[T]constf1: F1=f// why does this error?typeF2=<Textends'a'|'b'>(x: `${T}`)=>TypeMap[`${T}`]// and why does making the return type a template literal fix it?constf2: F2=f🙁 Actual behavior
On line 9 occurs -
Type '<T extends "a" | "b">(x: `${T}`) => TypeMap[T]' is not assignable to type 'F1'.
Type 'TypeMap[`${T}`]' is not assignable to type 'TypeMap[T]'.
Type 'TypeMap[`${T}`]' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.(2322)
🙂 Expected behavior
No error on line 9
🔎 Search Terms
mapped type template literal
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoE8AOECydPIDeAUMsnAFzIDkAgtacgEZXUBCDAvscQCYQIANnCgoEAexABnMMhhUAPKmQQAHpBC8pNONWQAfGk2oA+ABSqqAAwAkhVJysBKZAF4TaLLnwBtVAF0eMC9kADEARjdkJRV1CE1tal0DI1MLazsHZzcPDGw8TD9AiWlZGHCqCKiYZAB6WuQAdwALdGRecQhtMGbgbWgocSgAfiCQ0IAmKJi1DS0dPUNqY3NLZFt7Rxd3T3zfDaz-Ooa4TSbW9s7tAFs4AGtQAHNkHpRRMABXKBAXkLgXiDXTDCSDIQTASBQOCCOTAVTICGjEoyOQTSpTVxyIA
💻 Code
The unexpected error is marked by a comment in the code bellow. A second comment highlights a case, where this issue does not occur, even though the two cases should be identical, as far as i understand. Thank you Matt Kantor (@mkantor) for the minimalistic example. The issue has been discussed on the TS discord in various channels. The original discussion was an "ask for help" here - https://discord.com/channels/508357248330760243/1139519033809575966/1139519033809575966
🙁 Actual behavior
On line 9 occurs -
🙂 Expected behavior
No error on line 9