Skip to content

Commit

Permalink
2023-09-07T15:27:35.366Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 7, 2023
1 parent 98ca5d5 commit e465d84
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ never disappearing in unions
JSDoc section?
Setters in classes?
Add decorators when they're supported in vite

Non null assertion
23 changes: 23 additions & 0 deletions src/035-understanding-the-compiler/131-satisfies.problem.ts
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 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 src/035-understanding-the-compiler/131-satisfies.solution.ts
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;
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;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.

0 comments on commit e465d84

Please sign in to comment.