Skip to content

Characters count as both prefix and suffix of pattern literal #40772

Closed

Description

TypeScript Version: v4.1.0-dev20200925

Search Terms: pattern literal prefix suffix

Code

const s: `:${string}:` = ":";

Expected behavior:
Assignability error because the pattern `:${string}:` has two literal : characters, while ":" has only one.

Actual behavior:
No error

Playground Link

Related Issues: #40598

Activity

  1. jamesmfriedman commented on Sep 28, 2020

    @jamesmfriedman

    Related to this issue,

    • It's great that in dev you can use string as a value placeholder! This is a marked improvement from beta.
    • The ability to define a prefix or suffix for a key is very valuable, but currently neither of these usecases work:
    type CustomProps = Record<`x${string}`, any>;
    const a: CustomProps = {};
    a.x11 = ''; // ERRORS OUT
    
    type CustomProps ={[key: `x${string}`]:  any}; // ERRORS, key must be string or number
    const a: CustomProps = {};
    

    Would be amazing if this could work!

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions