type-fest/test-d/split.ts
Sindre Sorhus e3234d74aa Use import type
Closes #390
2022-04-09 19:04:14 +07:00

31 lines
800 B
TypeScript

import {expectType} from 'tsd';
import type {Split} from '../index';
declare function split<
S extends string,
Delimiter extends string,
>(string: S, separator: Delimiter): Split<S, Delimiter>;
const items = 'foo,bar,baz,waldo';
// General use.
expectType<['foo', 'bar', 'baz', 'waldo']>(split(items, ','));
// Missing replacement character in original string.
expectType<['foo,bar,baz,waldo']>(split(items, ' '));
// Empty string split (every character).
expectType<[
'f', 'o', 'o', ',', 'b', 'a', 'r', ',',
'b', 'a', 'z', ',', 'w', 'a', 'l', 'd', 'o',
]>(split(items, ''));
// Split single same character.
expectType<['', '']>(split(' ', ' '));
// Split empty string by empty string.
expectType<[]>(split('', ''));
// Split empty string by any string.
expectType<['']>(split('', ' '));