Skip to content

Commit 0b1d5f1

Browse files
chore: format
1 parent 6424b9c commit 0b1d5f1

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

docs/advanced/patterns_by_version.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,20 @@ type HorizontalAlignment = "left" | "center" | "right";
463463
// | "top-left" | "top-center" | "top-right"
464464
// | "middle-left" | "middle-center" | "middle-right"
465465
// | "bottom-left" | "bottom-center" | "bottom-right"
466-
declare function setAlignment(value: `${VerticalAlignment}-${HorizontalAlignment}`): void;
466+
declare function setAlignment(
467+
value: `${VerticalAlignment}-${HorizontalAlignment}`
468+
): void;
467469

468-
setAlignment("top-left"); // works!
470+
setAlignment("top-left"); // works!
469471
setAlignment("top-middel"); // error!
470-
setAlignment("top-pot"); // error! but good doughnuts if you're ever in Seattle
472+
setAlignment("top-pot"); // error! but good doughnuts if you're ever in Seattle
471473
```
472474

473475
Usecase 2 - Modeling dynaming string literal types:
474476

475477
```tsx
476478
type PropEventSource<T> = {
477-
on(eventName: `${string & keyof T}Changed`, callback: () => void): void;
479+
on(eventName: `${string & keyof T}Changed`, callback: () => void): void;
478480
};
479481

480482
/// Create a "watched object" with an 'on' method
@@ -487,14 +489,11 @@ To make string manipulation easier there are new generics: `Uppercase`, `Lowerca
487489
You can combine it with the `infer` keyword [like this](https://www.smashingmagazine.com/2021/01/dynamic-static-typing-typescript/#conditional-types-and-recursive-template-literal-types):
488490

489491
```ts
490-
type ParseRouteParams<Rte> =
491-
Rte extends `${string}/:${infer P}`
492-
? P
493-
: never;
492+
type ParseRouteParams<Rte> = Rte extends `${string}/:${infer P}` ? P : never;
494493

495-
type Params = ParseRouteParams<"/api/user/:userID"> // Params is "userID"
494+
type Params = ParseRouteParams<"/api/user/:userID">; // Params is "userID"
496495

497-
type NoParams = ParseRouteParams<"/api/user"> // NoParams is never --> no params!
496+
type NoParams = ParseRouteParams<"/api/user">; // NoParams is never --> no params!
498497
```
499498

500499
This feature is extremely flexible, see other usecase ideas here:

0 commit comments

Comments
 (0)