Skip to content

Template literal type ${string}${number}${string} errors on valid values #57355

Description

🔎 Search Terms

"${string}${number}${string}", "template literal types number between strings"

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about template literal types

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAtgTwMpQE4EswHMBcADAEgG9oNsBfYsAVzgCMBTVSktTLcvGAXhgHIoDaAEYATAGZB0PgG4AUAHoFMFTAB6GzRpgAVBAAcG-AERSoYyUKjG+MdBBhgQsAIYQI6LGBd0ANkagQGCgDIz5CVjIOKlpGZmJSdk4+ADooCAAKCVFRAEo5UEhYRBQo0XwEtgoY+iZOHn4zC1lFZVUtLV1QkyaJGzsHJ1d3T28-AKCQw34IxOqiGlrmPFT0rPEc-MLoeGQqrHEKhdi6yqj63j4LM1kYJRh9NwghGAAzEFQYCBA4I1QGNzgORAA

💻 Code

const myString:`${string}${number}${string}` = 'test123test';
//    ^^^^^^^^ Type '"test123test"' is not assignable to type '`${string}${number}${string}`'.ts(2322)
const myString2:`${string}${number}` = 'test123';
//    ^^^^^^^^ Type '"test123"' is not assignable to type '`${string}${number}`'.ts(2322)
const myString3:`${number}${string}` = '123test'; // passes for some reason

🙁 Actual behavior

Received error "Type '"test123test"' is not assignable to type '${string}${number}${string}'.ts(2322)" when pattern matches

🙂 Expected behavior

I expect it to match any literal string type that has a number within it

Additional information about the issue

My real use case is that I would like to be able to exclude/omit patterns like ${string}${number}${string}, but that's not possible since it doesn't match

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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