From 22a4b0b353ada328239a0acf85e00a42a6d9c36e Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Wed, 22 Sep 2021 11:50:58 +0300 Subject: [PATCH 1/2] fix: make deep properties of `PackageJson` optional --- source/package-json.d.ts | 14 +++++++------- test-d/package-json.ts | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/source/package-json.d.ts b/source/package-json.d.ts index bb985bffb..0921e7454 100644 --- a/source/package-json.d.ts +++ b/source/package-json.d.ts @@ -200,12 +200,12 @@ declare namespace PackageJson { Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided. */ postrestart?: string; - } & Record; + } & Partial>; /** Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL. */ - export type Dependency = Record; + export type Dependency = Partial>; /** Conditions which provide a way to resolve a package entry point based on the environment. @@ -253,7 +253,7 @@ declare namespace PackageJson { */ browser?: | string - | Record; + | Partial>; /** Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused. @@ -272,7 +272,7 @@ declare namespace PackageJson { /** Version selection map of TypeScript. */ - typesVersions?: Record>; + typesVersions?: Partial>>>; /** Location of the bundled TypeScript declaration file. Alias of `types`. @@ -426,7 +426,7 @@ declare namespace PackageJson { */ bin?: | string - | Record; + | Partial>; /** Filenames to put in place for the `man` program to find. @@ -488,7 +488,7 @@ declare namespace PackageJson { /** Indicate peer dependencies that are optional. */ - peerDependenciesMeta?: Record; + peerDependenciesMeta?: Partial>; /** Package names that are bundled when the package is published. @@ -504,7 +504,7 @@ declare namespace PackageJson { Engines that this package runs on. */ engines?: { - [EngineName in 'npm' | 'node' | string]: string; + [EngineName in 'npm' | 'node' | string]?: string; }; /** diff --git a/test-d/package-json.ts b/test-d/package-json.ts index f08c48c65..5f7022d1e 100644 --- a/test-d/package-json.ts +++ b/test-d/package-json.ts @@ -16,7 +16,7 @@ expectType(packageJson.contributors); expectType(packageJson.maintainers); expectType(packageJson.files); expectType(packageJson.main); -expectType | undefined>(packageJson.bin); +expectType> | undefined>(packageJson.bin); expectType(packageJson.types); expectType(packageJson.typings); expectType(packageJson.man); @@ -36,7 +36,7 @@ expectType(packageJson.bundleDependencies); expectType(packageJson.bundledDependencies); expectType(packageJson.resolutions); expectType(packageJson.workspaces); -expectType | undefined>(packageJson.engines); +expectType> | undefined>(packageJson.engines); expectType(packageJson.engineStrict); expectAssignable< | undefined @@ -67,4 +67,17 @@ expectType< >(packageJson.esnext); expectType(packageJson.jspm); +// Undefined assigns +expectAssignable({dep: undefined}); +expectAssignable({engine: undefined}); +expectAssignable({unknownScript: undefined}); +expectAssignable({bin: undefined}); +expectAssignable({ + '>=4': { + '*': ['src'], + somethingElse: undefined, + }, + '<4': undefined, +}); + expectNotAssignable>(packageJson); From ec64dfe57697c0cf8cd0f54f4248fe4ffa654b58 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Wed, 22 Sep 2021 11:55:31 +0300 Subject: [PATCH 2/2] fix: make deep properties of `TsConfigJson` optional --- source/tsconfig-json.d.ts | 2 +- test-d/tsconfig-json.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/tsconfig-json.d.ts b/source/tsconfig-json.d.ts index 9faa5c93d..d22e41e45 100644 --- a/source/tsconfig-json.d.ts +++ b/source/tsconfig-json.d.ts @@ -706,7 +706,7 @@ declare namespace TsConfigJson { /** Specify path mapping to be computed relative to baseUrl option. */ - paths?: Record; + paths?: Partial>; /** List of TypeScript language server plugins to load. diff --git a/test-d/tsconfig-json.ts b/test-d/tsconfig-json.ts index 3012675fe..69c3122cd 100644 --- a/test-d/tsconfig-json.ts +++ b/test-d/tsconfig-json.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectAssignable, expectType} from 'tsd'; import {TsConfigJson} from '../index'; const tsConfig: TsConfigJson = {}; @@ -11,3 +11,6 @@ expectType(tsConfig.files); expectType(tsConfig.include); expectType(tsConfig.references); expectType(tsConfig.typeAcquisition); + +// Undefined assigns +expectAssignable['paths']>({path: undefined});