Relative Content

Tag Archive for typescriptloops

Typescript how to extract multiple literal from a string

type X<T>=T extends `${string}${‘*’}${infer A}${‘*’}${string}${‘*’}${infer A}${‘*’}${string}`?A:never type Y=X<‘g*a*gggggg*h*’> My objective is to extract all literals from a string based on certain pattern. In the code above, I wanna extract literals with surrounding ‘*’. Hence, type Y = ‘a’|’h’. But the problem is a string can have any number of matched-pattern-literal and I do not know […]