Implement EndsWith<T, U>
which takes two exact string types and returns whether T
ends with U
For example:
type a = EndsWith<'abc', 'bc'> // expected to be true
type b = EndsWith<'abc', 'abc'> // expected to be true
type c = EndsWith<'abc', 'd'> // expected to be false
/* _____________ Your Code Here _____________ */
type EndsWith<T extends string, U extends string> = T extends `${string}${U}` ? true: false
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<EndsWith<'abc', 'bc'>, true>>,
Expect<Equal<EndsWith<'abc', 'abc'>, true>>,
Expect<Equal<EndsWith<'abc', 'd'>, false>>,
]
标签:Typescript,false,_____________,type,EndsWith,Medium,Expect,true From: https://www.cnblogs.com/Answer1215/p/16790250.html