[Typescript] 48. Medium - EndsWith
typescript Medium 48
2023-09-14 08:59:11 时间
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] Create an Object Whose Keys Are Derived From a Union
- [Typescript] Different types for Getter / Setter in a class
- [Typescript] 92. Medium - PathParams
- [Typescript] 51. Medium - Mutable
- [TypeScript] Make typescript stick - 2
- [Typescript] “keyof”, Generics and Lookup Types
- [Typescript] Make your optional fields required in TypeScript
- [Algorithm] Median Maintenance algorithm implementation using TypeScript / JavaScript
- [TypeScript] Function Overloads in Typescript
- [Typescript] Transform a Discriminated Union into a Union
- [Typescript] Get All of an Object’s Values
- [Typescript] Extracting Members of a Discriminated union - Extract<T, U>
- [Typescript] 133. Medium - All
- [Typescript] 79. Medium - MapTypes
- [Typescript] 67. Medium - Chunk
- [Typescript] Get a TypeScript package ready for release to NPM
- [Typescript] 23. Medium - Promise.all
- [Typescript] 21. Medium - Last of Array
- [Typescript] ts-expect-error
- [Typescript] Generics constraint
- [Typescript] Use the Nullish Coalescing Operator in TypeScript (isNil)
- [Typescript] Simplify iteration of custom data structures in TypeScript with iterators (backwards iteration with for ... of.. loop)
- [Vue +TS] Use Two-Way Binding in Vue Using @Model Decorator with TypeScript
- 关于 TypeScript 内 constructor signature 的一些失败尝试
- TypeScript中的实用方法