Open utterances-bot opened 2 years ago
Why not use ${string}
instead of ${any}
? It can't really be anything else, can it?
@DaniGuardiola if it works with a string
than it's ok too. I chose it to be an indicator to show I don't care about the end.
The solution above is simpler than mine. Here is mine just as alternative:
type EndsWith<T extends string, U extends string, acc extends string = ''> = U extends ''
? true
: T extends `${infer rest}${infer end}`
? end extends ''
? `${rest}${acc}` extends U ? true : false
: `${end}${acc}` extends U ? true : EndsWith<rest, U, `${end}${acc}`>
: never
EndsWith
This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges.
https://ghaiklor.github.io/type-challenges-solutions/en/medium-endswith.html