-
Notifications
You must be signed in to change notification settings - Fork 136
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
fb92816
commit a868d1e
Showing
11 changed files
with
232 additions
and
8 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
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
7 changes: 0 additions & 7 deletions
7
src/020-objects/068-omit-and-pick-cant-discribute.explainer.ts
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
type User = { | ||
id: string; | ||
name: string; | ||
age: number; | ||
imageId: string; | ||
}; | ||
|
||
type Organisation = { | ||
id: string; | ||
name: string; | ||
address: string; | ||
imageId: string; | ||
}; | ||
|
||
type Product = { | ||
id: string; | ||
name: string; | ||
price: number; | ||
imageId: string; | ||
}; | ||
|
||
type Entity = User | Organisation | Product; | ||
|
||
type EntityWithoutId = Omit<Entity, "id">; | ||
// ^? | ||
|
||
type test = Expect< | ||
Equal< | ||
EntityWithoutId, | ||
| { | ||
name: string; | ||
age: number; | ||
imageId: string; | ||
} | ||
| { | ||
name: string; | ||
address: string; | ||
imageId: string; | ||
} | ||
| { | ||
name: string; | ||
price: number; | ||
imageId: string; | ||
} | ||
> | ||
>; |
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,50 @@ | ||
type User = { | ||
id: string; | ||
name: string; | ||
age: number; | ||
imageId: string; | ||
}; | ||
|
||
type Organisation = { | ||
id: string; | ||
name: string; | ||
address: string; | ||
imageId: string; | ||
}; | ||
|
||
type Product = { | ||
id: string; | ||
name: string; | ||
price: number; | ||
imageId: string; | ||
}; | ||
|
||
type Entity = User | Organisation | Product; | ||
|
||
type DistributiveOmit<T, K extends PropertyKey> = T extends any | ||
? Omit<T, K> | ||
: never; | ||
|
||
type EntityWithoutId = DistributiveOmit<Entity, "id">; | ||
// ^? | ||
|
||
type test = Expect< | ||
Equal< | ||
EntityWithoutId, | ||
| { | ||
name: string; | ||
age: number; | ||
imageId: string; | ||
} | ||
| { | ||
name: string; | ||
address: string; | ||
imageId: string; | ||
} | ||
| { | ||
name: string; | ||
price: number; | ||
imageId: string; | ||
} | ||
> | ||
>; |
29 changes: 29 additions & 0 deletions
29
src/020-objects/069-omit-or-pick-more-than-one-thing.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,29 @@ | ||
interface Product { | ||
id: number; | ||
name: string; | ||
price: number; | ||
description: string; | ||
} | ||
|
||
const addProduct = (productInfo: unknown) => { | ||
// Do something with the productInfo | ||
}; | ||
|
||
addProduct({ | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); | ||
|
||
addProduct({ | ||
// @ts-expect-error | ||
id: 1, | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); | ||
|
||
addProduct({ | ||
// @ts-expect-error | ||
price: 10, | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/020-objects/069-omit-or-pick-more-than-one-thing.solution.1.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,29 @@ | ||
interface Product { | ||
id: number; | ||
name: string; | ||
price: number; | ||
description: string; | ||
} | ||
|
||
const addProduct = (productInfo: Omit<Product, "id" | "price">) => { | ||
// Do something with the productInfo | ||
}; | ||
|
||
addProduct({ | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); | ||
|
||
addProduct({ | ||
// @ts-expect-error | ||
id: 1, | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); | ||
|
||
addProduct({ | ||
// @ts-expect-error | ||
price: 10, | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/020-objects/069-omit-or-pick-more-than-one-thing.solution.2.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,29 @@ | ||
interface Product { | ||
id: number; | ||
name: string; | ||
price: number; | ||
description: string; | ||
} | ||
|
||
const addProduct = (productInfo: Pick<Product, "name" | "description">) => { | ||
// Do something with the productInfo | ||
}; | ||
|
||
addProduct({ | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); | ||
|
||
addProduct({ | ||
// @ts-expect-error | ||
id: 1, | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); | ||
|
||
addProduct({ | ||
// @ts-expect-error | ||
price: 10, | ||
name: "Book", | ||
description: "A book about Dragons", | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.