-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d8ee85
commit f40f234
Showing
35 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/038-unions-and-narrowing/039-combining-unions.problem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type HttpCode = "400" | "401" | "404" | "500" | "200" | "201" | "204"; | ||
|
||
const handleErrorCase = (code: string) => { | ||
// An imaginary function where we only handle the errors | ||
|
||
type test = Expect<Equal<typeof code, "400" | "401" | "404" | "500">>; | ||
}; | ||
|
||
const handleSuccessCase = (code: string) => { | ||
// An imaginary function where we only handle the success cases | ||
|
||
type test = Expect<Equal<typeof code, "200" | "201" | "204">>; | ||
}; | ||
|
||
const handleAllCase = (code: HttpCode) => { | ||
// An imaginary function where we handle all the cases | ||
|
||
type test = Expect< | ||
Equal<typeof code, "200" | "201" | "204" | "400" | "401" | "404" | "500"> | ||
>; | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/038-unions-and-narrowing/039-combining-unions.solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
type SuccessCode = "200" | "201" | "204"; | ||
type ErrorCode = "400" | "401" | "404" | "500"; | ||
|
||
type HttpCode = SuccessCode | ErrorCode; | ||
|
||
const handleErrorCase = (code: ErrorCode) => { | ||
// An imaginary function where we only handle the errors | ||
|
||
type test = Expect<Equal<typeof code, "400" | "401" | "404" | "500">>; | ||
}; | ||
|
||
const handleSuccessCase = (code: SuccessCode) => { | ||
// An imaginary function where we only handle the success cases | ||
|
||
type test = Expect<Equal<typeof code, "200" | "201" | "204">>; | ||
}; | ||
|
||
const handleAllCase = (code: HttpCode) => { | ||
// An imaginary function where we handle all the cases | ||
|
||
type test = Expect< | ||
Equal<typeof code, "200" | "201" | "204" | "400" | "401" | "404" | "500"> | ||
>; | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.