Skip to content

Commit

Permalink
2023-09-08T09:28:20.263Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 8, 2023
1 parent 5a1b68a commit 8e4623c
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 0 deletions.
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,
);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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,
);
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,
);
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,
);
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.

0 comments on commit 8e4623c

Please sign in to comment.