From f2aae51776210926b4e7601dfaa218a1d09827ac Mon Sep 17 00:00:00 2001 From: Vitaly Date: Tue, 24 May 2022 15:09:05 +0300 Subject: [PATCH] Fix deep properties of `PackageJson` and `TsConfigJson` (#269) --- source/package-json.d.ts | 14 +++++++------- source/tsconfig-json.d.ts | 2 +- test-d/package-json.ts | 17 +++++++++++++++-- test-d/tsconfig-json.ts | 5 ++++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/source/package-json.d.ts b/source/package-json.d.ts index 81aa7786d..1bccfd041 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. @@ -262,7 +262,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. @@ -281,7 +281,7 @@ declare namespace PackageJson { /** Version selection map of TypeScript. */ - typesVersions?: Record>; + typesVersions?: Partial>>>; /** Location of the bundled TypeScript declaration file. Alias of `types`. @@ -442,7 +442,7 @@ declare namespace PackageJson { */ bin?: | string - | Record; + | Partial>; /** Filenames to put in place for the `man` program to find. @@ -504,7 +504,7 @@ declare namespace PackageJson { /** Indicate peer dependencies that are optional. */ - peerDependenciesMeta?: Record; + peerDependenciesMeta?: Partial>; /** Package names that are bundled when the package is published. @@ -520,7 +520,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/source/tsconfig-json.d.ts b/source/tsconfig-json.d.ts index 18a7294c5..26b8851de 100644 --- a/source/tsconfig-json.d.ts +++ b/source/tsconfig-json.d.ts @@ -713,7 +713,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/package-json.ts b/test-d/package-json.ts index eea18dbd5..782006e13 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); diff --git a/test-d/tsconfig-json.ts b/test-d/tsconfig-json.ts index e6a3b4059..337a48d77 100644 --- a/test-d/tsconfig-json.ts +++ b/test-d/tsconfig-json.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectType, expectAssignable} from 'tsd'; import type {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});