/
trim.ts
22 lines (18 loc) · 973 Bytes
/
trim.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import {expectError, expectType} from 'tsd';
import {Trim} from '../ts41';
let leftSpaced: {withSpaces: ' foo'; trimmed: 'foo'};
let rightSpaced: {withSpaces: 'bar '; trimmed: 'bar'};
let onceSpaced: {withSpaces: ' baz '; trimmed: 'baz'};
let twiceSpaced: {withSpaces: ' waldo '; trimmed: 'waldo'};
type TrimmedFromLeft = Trim<typeof leftSpaced.withSpaces>;
type TrimmedFromRight = Trim<typeof rightSpaced.withSpaces>;
type TrimmedOnce = Trim<typeof onceSpaced.withSpaces>;
type TrimmedTwice = Trim<typeof twiceSpaced.withSpaces>;
expectType<TrimmedFromLeft>(leftSpaced.trimmed);
expectType<TrimmedFromRight>(rightSpaced.trimmed);
expectType<TrimmedOnce>(onceSpaced.trimmed);
expectType<TrimmedTwice>(twiceSpaced.trimmed);
expectError(expectType<TrimmedFromLeft>(rightSpaced.trimmed));
expectError(expectType<TrimmedFromRight>(onceSpaced.trimmed));
expectError(expectType<TrimmedOnce>(twiceSpaced.trimmed));
expectError(expectType<TrimmedTwice>(leftSpaced.trimmed));