Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Literal with infer does not handle surrogate pairs #41149

Open
AnyhowStep opened this issue Oct 17, 2020 · 1 comment
Open

Template Literal with infer does not handle surrogate pairs #41149

AnyhowStep opened this issue Oct 17, 2020 · 1 comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@AnyhowStep
Copy link
Contributor

AnyhowStep commented Oct 17, 2020

TypeScript Version: 4.1.0-dev.20201015

Search Terms:
template literal, surrogate pair, infer

Code

type Head<StrT extends string> = StrT extends `${infer HeadT}${string}` ? HeadT : never;

type Tail<StrT extends string> = StrT extends `${string}${infer TailT}` ? TailT : never;

type TestHead = Head<"𡁻">
type TestTail = Tail<"𡁻">

Expected behavior:
Should handle surrogate pairs properly

Actual behavior:
image

image

Playground Link:
Playground

Related Issues:
Searched for "template literal surrogate pair" and didn't find anything

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Nov 3, 2020
@RyanCavanaugh
Copy link
Member

We're doing what JS does here for the most part. We can revisit if there's a ton of feedback but this is just very difficult to handle and we don't expect to see these kinds of strings in practice.

> "𡁻".length
2
> "𡁻"[0]
"�"
> "𡁻"[1]
"�"
> "𡁻".match(/(.)(.)/)
(3) ["𡁻", "�", "�", index: 0, input: "𡁻", groups: undefined]
0: "𡁻"
1: "�"
2: "�"
groups: undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants