Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 committed Sep 15, 2022
1 parent 6df18e3 commit 2ce0783
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/basic.d.ts
Expand Up @@ -19,7 +19,7 @@ This type can be useful to enforce some input to be JSON-compatible or as a supe
@category JSON
*/
export type JsonObject = {[Key in string]?: JsonValue};
export type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};

/**
Matches a JSON array.
Expand Down
19 changes: 16 additions & 3 deletions test-d/package-json.ts
@@ -1,5 +1,5 @@
import {expectType, expectAssignable, expectNotAssignable} from 'tsd';
import type {PackageJson, LiteralUnion} from '../index';
import {expectType, expectAssignable, expectNotAssignable, expectError} from 'tsd';
import type {PackageJson, LiteralUnion, JsonObject} from '../index';

const packageJson: PackageJson = {};

Expand Down Expand Up @@ -81,4 +81,17 @@ expectAssignable<typeof packageJson['typesVersions']>({
'<4': undefined,
});

expectNotAssignable<Record<string, unknown>>(packageJson);
// Must reject an object that contains properties with `undefined` values.
// See https://github.com/sindresorhus/type-fest/issues/272
declare function setConfig(config: JsonObject): void;

expectError(setConfig({bugs: undefined}));
expectError(setConfig({bugs: {life: undefined}}));

expectNotAssignable<JsonObject>({bugs: undefined});
expectNotAssignable<JsonObject>({bugs: {life: undefined}});

expectAssignable<JsonObject>({});
expectAssignable<JsonObject>({bugs: 42});
expectAssignable<JsonObject>({bugs: [42]});
expectAssignable<JsonObject>({bugs: {life: 42}});

0 comments on commit 2ce0783

Please sign in to comment.