-
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
5a1b68a
commit 8e4623c
Showing
8 changed files
with
204 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const acceptAnythingExceptNullOrUndefined = (input) => {}; | ||
|
||
acceptAnythingExceptNullOrUndefined("hello"); | ||
acceptAnythingExceptNullOrUndefined(42); | ||
acceptAnythingExceptNullOrUndefined(true); | ||
acceptAnythingExceptNullOrUndefined(Symbol("foo")); | ||
acceptAnythingExceptNullOrUndefined({}); | ||
acceptAnythingExceptNullOrUndefined([]); | ||
acceptAnythingExceptNullOrUndefined(() => {}); | ||
acceptAnythingExceptNullOrUndefined(/foo/); | ||
acceptAnythingExceptNullOrUndefined(new Error("foo")); | ||
|
||
acceptAnythingExceptNullOrUndefined( | ||
// @ts-expect-error | ||
null, | ||
); | ||
acceptAnythingExceptNullOrUndefined( | ||
// @ts-expect-error | ||
undefined, | ||
); |
8 changes: 8 additions & 0 deletions
8
src/035-understanding-the-compiler/135-empty-object-type.solution.1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions
8
src/035-understanding-the-compiler/135-empty-object-type.solution.2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,20 @@ | ||
const acceptAnythingExceptNullOrUndefined = (input: {}) => {}; | ||
|
||
acceptAnythingExceptNullOrUndefined("hello"); | ||
acceptAnythingExceptNullOrUndefined(42); | ||
acceptAnythingExceptNullOrUndefined(true); | ||
acceptAnythingExceptNullOrUndefined(Symbol("foo")); | ||
acceptAnythingExceptNullOrUndefined({}); | ||
acceptAnythingExceptNullOrUndefined([]); | ||
acceptAnythingExceptNullOrUndefined(() => {}); | ||
acceptAnythingExceptNullOrUndefined(/foo/); | ||
acceptAnythingExceptNullOrUndefined(new Error("foo")); | ||
|
||
acceptAnythingExceptNullOrUndefined( | ||
// @ts-expect-error | ||
null, | ||
); | ||
acceptAnythingExceptNullOrUndefined( | ||
// @ts-expect-error | ||
undefined, | ||
); |
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,48 @@ | ||
const acceptOnlyEmptyObject = (input: {}) => {}; | ||
|
||
acceptOnlyEmptyObject({}); | ||
|
||
acceptOnlyEmptyObject({ | ||
// @ts-expect-error | ||
a: 1, | ||
}); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
"hello", | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
42, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
true, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
Symbol("foo"), | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
[], | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
() => {}, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
/foo/, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
new Error("foo"), | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
null, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
undefined, | ||
); |
48 changes: 48 additions & 0 deletions
48
src/035-understanding-the-compiler/136-truly-empty-object.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,48 @@ | ||
const acceptOnlyEmptyObject = (input: Record<PropertyKey, never>) => {}; | ||
|
||
acceptOnlyEmptyObject({}); | ||
|
||
acceptOnlyEmptyObject({ | ||
// @ts-expect-error | ||
a: 1, | ||
}); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
"hello", | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
42, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
true, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
Symbol("foo"), | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
[], | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
() => {}, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
/foo/, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
new Error("foo"), | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
null, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
undefined, | ||
); |
52 changes: 52 additions & 0 deletions
52
src/035-understanding-the-compiler/136-truly-empty-object.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,52 @@ | ||
// From https://github.com/sindresorhus/type-fest/issues/395#issuecomment-1162156994 | ||
declare const tag: unique symbol; | ||
type EmptyObject = { [tag]?: never }; | ||
|
||
const acceptOnlyEmptyObject = (input: Record<PropertyKey, never>) => {}; | ||
|
||
acceptOnlyEmptyObject({}); | ||
|
||
acceptOnlyEmptyObject({ | ||
// @ts-expect-error | ||
a: 1, | ||
}); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
"hello", | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
42, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
true, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
Symbol("foo"), | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
[], | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
() => {}, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
/foo/, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
new Error("foo"), | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
null, | ||
); | ||
acceptOnlyEmptyObject( | ||
// @ts-expect-error | ||
undefined, | ||
); |
Empty file.