题目
中文
实现 TrimRight<T>
,它接收确定的字符串类型并返回一个新的字符串,其中新返回的字符串删除了原字符串结尾的空白字符串。
例如
type Trimed = TrimRight<' Hello World '>; // 应推导出 ' Hello World'
English
Implement TrimRight<T>
which takes an exact string type and returns a new string with the whitespace ending removed.
For example:
type Trimed = TrimRight<' Hello World '>; // expected to be ' Hello World'
答案
type TrimRight<S extends string> = S extends `${infer L}${'\n' | '\t' | ' '}`
? TrimRight<L>
: S;
标签:Typescript,string,TrimRight,体操,字符串,World,type
From: https://www.cnblogs.com/laggage/p/type-challenge-trim-right.html