-
Notifications
You must be signed in to change notification settings - Fork 137
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
98ca5d5
commit e465d84
Showing
23 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
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
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.
23 changes: 23 additions & 0 deletions
23
src/035-understanding-the-compiler/131-satisfies.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,23 @@ | ||
type Color = | ||
| string | ||
| { | ||
r: number; | ||
g: number; | ||
b: number; | ||
}; | ||
|
||
const config: Record<string, Color> = { | ||
foreground: { r: 255, g: 255, b: 255 }, | ||
background: { r: 0, g: 0, b: 0 }, | ||
border: "transparent", | ||
}; | ||
|
||
config.border.toUpperCase(); | ||
|
||
console.log(config.foreground.r); | ||
|
||
// @ts-expect-error | ||
config.primary; | ||
|
||
// @ts-expect-error | ||
config.secondary; |
15 changes: 15 additions & 0 deletions
15
src/035-understanding-the-compiler/131-satisfies.solution.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
src/035-understanding-the-compiler/131-satisfies.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,23 @@ | ||
type Color = | ||
| string | ||
| { | ||
r: number; | ||
g: number; | ||
b: number; | ||
}; | ||
|
||
const config = { | ||
foreground: { r: 255, g: 255, b: 255 }, | ||
background: { r: 0, g: 0, b: 0 }, | ||
border: "transparent", | ||
} satisfies Record<string, Color>; | ||
|
||
config.border.toUpperCase(); | ||
|
||
console.log(config.foreground.r); | ||
|
||
// @ts-expect-error | ||
config.primary; | ||
|
||
// @ts-expect-error | ||
config.secondary; |
61 changes: 61 additions & 0 deletions
61
src/035-understanding-the-compiler/132-satisfies-vs-as-vs-variable-annotations.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,61 @@ | ||
// 1 | ||
|
||
const obj = {} as Record<string, number>; | ||
|
||
obj.a = 1; | ||
|
||
obj.b = 2; | ||
|
||
type test = Expect<Equal<typeof obj.a, number>>; | ||
|
||
// 2 | ||
|
||
const menuConfig: Record< | ||
string, | ||
| { | ||
label: string; | ||
link: string; | ||
} | ||
| { | ||
label: string; | ||
children: { | ||
label: string; | ||
link: string; | ||
}[]; | ||
} | ||
> = { | ||
home: { | ||
label: "Home", | ||
link: "/home", | ||
}, | ||
services: { | ||
label: "Services", | ||
children: [ | ||
{ | ||
label: "Consulting", | ||
link: "/services/consulting", | ||
}, | ||
{ | ||
label: "Development", | ||
link: "/services/development", | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
type tests = [ | ||
Expect<Equal<typeof menuConfig.home.label, string>>, | ||
Expect< | ||
Equal< | ||
typeof menuConfig.services.children, | ||
{ | ||
label: string; | ||
link: string; | ||
}[] | ||
> | ||
>, | ||
]; | ||
|
||
// 3 | ||
|
||
const element = document.getElementById("app") satisfies HTMLElement; |
17 changes: 17 additions & 0 deletions
17
...rstanding-the-compiler/132-satisfies-vs-as-vs-variable-annotations.solution.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions
61
src/035-understanding-the-compiler/132-satisfies-vs-as-vs-variable-annotations.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,61 @@ | ||
// 1 | ||
|
||
const obj = {} as Record<string, number>; | ||
|
||
obj.a = 1; | ||
|
||
obj.b = 2; | ||
|
||
type test = Expect<Equal<typeof obj.a, number>>; | ||
|
||
// 2 | ||
|
||
const menuConfig: Record< | ||
string, | ||
| { | ||
label: string; | ||
link: string; | ||
} | ||
| { | ||
label: string; | ||
children: { | ||
label: string; | ||
link: string; | ||
}[]; | ||
} | ||
> = { | ||
home: { | ||
label: "Home", | ||
link: "/home", | ||
}, | ||
services: { | ||
label: "Services", | ||
children: [ | ||
{ | ||
label: "Consulting", | ||
link: "/services/consulting", | ||
}, | ||
{ | ||
label: "Development", | ||
link: "/services/development", | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
type tests = [ | ||
Expect<Equal<typeof menuConfig.home.label, string>>, | ||
Expect< | ||
Equal< | ||
typeof menuConfig.services.children, | ||
{ | ||
label: string; | ||
link: string; | ||
}[] | ||
> | ||
>, | ||
]; | ||
|
||
// 3 | ||
|
||
const element = document.getElementById("app") satisfies HTMLElement; |
Empty file.
Empty file.