danvk / effective-typescript

Effective TypeScript 2nd Edition: 83 Specific Ways to Improve Your TypeScript
https://effectivetypescript.com
Other
1.53k stars 226 forks source link

TypeScript Splits the Atom! #10

Open danvk opened 2 years ago

danvk commented 2 years ago

TypeScript Splits the Atom!

https://effectivetypescript.com/2020/11/05/template-literal-types/

danvk commented 2 years ago

Comment by Bob on 2020-11-22 12:53:

Where does Capitalize come from?

danvk commented 2 years ago

Comment by danvdk on 2020-11-22 01:50:

It's one of four new built-in generics in TS 4.1: Uppercase, Lowercase, Capitalize and Uncapitalize. Take a look at the TypeScript 4.1 release post.

danvk commented 2 years ago

Comment by Pomar81 (pomar81) on 2020-11-22 06:51:

Unfortunately type OnString = `on${string}` gives an error in playgroud

https://www.typescriptlang....

danvk commented 2 years ago

Comment by danvdk on 2020-11-22 07:17:

You're on the 4.1 beta for the playground. Try it on the 4.1 release (4.1.2) or a nightly, it'll work: https://www.typescriptlang....

danvk commented 2 years ago

Comment by Pomar81 (pomar81) on 2020-11-23 05:13:

it will be great if we can type something like
type WithData = {[key: `data-${string}`]: string}

danvk commented 2 years ago

_Comment by Tomás Fox (tom_s_fox) on 2021-09-02 01:51:_

This is now possible in 4.4: https://devblogs.microsoft....