Skip to content

Commit

Permalink
Document Uppercase, Lowercase, Capitalize and Uncapitalize bu…
Browse files Browse the repository at this point in the history
…ilt-in types (#163)

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
kainiedziela and sindresorhus committed Dec 16, 2020
1 parent d232c19 commit 2e4b3f3
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,90 @@ There are many advanced types most users don't know about.
```
</details>

- [`Uppercase<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms every character in a string into uppercase.
<details>
<summary>
Example
</summary>

```ts
type T = Uppercase<'hello'>; // 'HELLO'

type T2 = Uppercase<'foo' | 'bar'>; // 'FOO' | 'BAR'

type T3<S extends string> = Uppercase<`aB${S}`>;
type T4 = T30<'xYz'>; // 'ABXYZ'

type T5 = Uppercase<string>; // string
type T6 = Uppercase<any>; // any
type T7 = Uppercase<never>; // never
type T8 = Uppercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
```
</details>

- [`Lowercase<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms every character in a string into lowercase.
<details>
<summary>
Example
</summary>

```ts
type T = Lowercase<'HELLO'>; // 'hello'

type T2 = Lowercase<'FOO' | 'BAR'>; // 'foo' | 'bar'

type T3<S extends string> = Lowercase<`aB${S}`>;
type T4 = T32<'xYz'>; // 'abxyz'

type T5 = Lowercase<string>; // string
type T6 = Lowercase<any>; // any
type T7 = Lowercase<never>; // never
type T8 = Lowercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
```
</details>

- [`Capitalize<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms the first character in a string into uppercase.
<details>
<summary>
Example
</summary>

```ts
type T = Capitalize<'hello'>; // 'Hello'

type T2 = Capitalize<'foo' | 'bar'>; // 'Foo' | 'Bar'

type T3<S extends string> = Capitalize<`aB${S}`>;
type T4 = T32<'xYz'>; // 'ABxYz'

type T5 = Capitalize<string>; // string
type T6 = Capitalize<any>; // any
type T7 = Capitalize<never>; // never
type T8 = Capitalize<42>; // Error, type 'number' does not satisfy the constraint 'string'
```
</details>

- [`Uncapitalize<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms the first character in a string into lowercase.
<details>
<summary>
Example
</summary>

```ts
type T = Uncapitalize<'Hello'>; // 'hello'

type T2 = Uncapitalize<'Foo' | 'Bar'>; // 'foo' | 'bar'

type T3<S extends string> = Uncapitalize<`AB${S}`>;
type T4 = T30<'xYz'>; // 'aBxYz'

type T5 = Uncapitalize<string>; // string
type T6 = Uncapitalize<any>; // any
type T7 = Uncapitalize<never>; // never
type T8 = Uncapitalize<42>; // Error, type 'number' does not satisfy the constraint 'string'
```
</details>

You can find some examples in the [TypeScript docs](https://www.typescriptlang.org/docs/handbook/advanced-types.html#predefined-conditional-types).

## Maintainers
Expand Down

0 comments on commit 2e4b3f3

Please sign in to comment.