-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathnon-empty-string.d.ts
More file actions
30 lines (21 loc) · 809 Bytes
/
non-empty-string.d.ts
File metadata and controls
30 lines (21 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
Matches any non-empty string.
This is useful when you need a string that is not empty, for example, as a function parameter.
NOTE:
- This returns `never` not just when instantiated with an empty string, but also when an empty string is a subtype of the instantiated type, like `string` or `Uppercase<string>`.
@example
```
import type {NonEmptyString} from 'type-fest';
declare function foo<T extends string>(string: NonEmptyString<T>): void;
foo('a');
//=> OK
foo('');
//=> Error: Argument of type '""' is not assignable to parameter of type 'never'.
declare const someString: string
foo(someString);
//=> Error: Argument of type 'string' is not assignable to parameter of type 'never'.
```
@category String
*/
export type NonEmptyString<T extends string> = '' extends T ? never : T;
export {};