首页 > 其他分享 >[Typescript] 48. Medium - EndsWith

[Typescript] 48. Medium - EndsWith

时间:2022-10-14 01:44:22浏览次数:50  
标签:Typescript false _____________ type EndsWith Medium Expect true

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

相关文章