Closed
Description
Bug Report
🔎 Search Terms
String index templates
Template String Pattern Index Signatures
🕗 Version & Regression Information
Seen on 4.4.3
- String Index Templates are a new feature with 4.4.2/3
⏯ Playground Link
💻 Code
// Violates additivity
type T1 = Record<`${string}`,any>
const t1:T1 = {'':0} // pass (expected)
type T2 = Record<`${number}`,any>
const t2_1spaces:T2 = {' ':0} // pass (expected)
type T3 = Record<`${number}${string}`,any>
const t3_1spaces:T3 = {' ':0} // pass (expected)
type T4 = Record<`${number}${string}${number}`,any>
const t4_0spaces:T4 = {'':0} // fail (expected)
const t4_1spaces:T4 = {' ':0} // fail (expected)
const t4_2spaces:T4 = {' ':0} // fail (UNEXPECTED) <------------
const t4_3spaces:T4 = {' ':0} // pass (expected)
const t4_4:T4 = {'11':0} // fail (UNEXPECTED) <------------
const t4_5:T4 = {'111':0} // pass (expected)
type X<T extends number|string> = Record<T,any>
type NS = `${number}${string}`
type N = `${number}`
type NSN = `${NS}${N}`
type A=X<NS>
type B=X<N>
type C=X<NSN>
const a:A = {'1':null} // pass (expected)
const b:B = {'1':null} // pass (expected)
const c:C = {'11':null} // fail (UNEXPECTED) <---------------------------
🙁 Actual behavior
If two templates are concatenated, that result will not accept all concatenations of originally accepted strings.
(More narrow assessment: ${number}${string}${number} should be equivalent to ${number}${string}, but isn't.)
🙂 Expected behavior
If two templates are concatenated, that result will accept all concatenations of originally accepted strings.
(More narrow assessment: ${number}${string}${number} should be equivalent to ${number}${string}.)