-
-
Notifications
You must be signed in to change notification settings - Fork 720
Expand file tree
/
Copy pathstring-length.d.ts
More file actions
38 lines (27 loc) · 717 Bytes
/
Copy pathstring-length.d.ts
File metadata and controls
38 lines (27 loc) · 717 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
31
32
33
34
35
36
37
38
import type {StringToArray} from './string-to-array.d.ts';
/**
Returns the length of the given string.
@example
```
import type {StringLength} from 'type-fest';
type A = StringLength<'abcde'>;
//=> 5
type B = StringLength<'abcde' | 'fgh'>;
//=> 3 | 5
```
For non-literal strings, the result is `number` because the length of a non-literal string can be any number.
@example
```
import type {StringLength} from 'type-fest';
type A = StringLength<string>;
//=> number
type B = StringLength<Uppercase<string>>;
//=> number
type C = StringLength<`${string}abc`>;
//=> number
```
@category String
@category Template literal
*/
export type StringLength<S extends string> = StringToArray<S>['length'];
export {};