Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Concatention of string index templates ${number}${string}${number} is not additive w.r.t. accepted strings.Β #46124

Copy link
Copy link
@craigphicks

Description

@craigphicks
Issue body actions

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

playground

πŸ’» 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}.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bugThe 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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.