diff --git a/source/package-json.d.ts b/source/package-json.d.ts index 737751898..599155381 100644 --- a/source/package-json.d.ts +++ b/source/package-json.d.ts @@ -224,7 +224,10 @@ declare namespace PackageJson { string >; - type ExportConditions = {[condition in ExportCondition]: Exports}; + /** + A mapping of conditions and the paths to which they resolve. + */ + type ExportConditions = {[condition in ExportCondition]?: Exports}; /** Entry points of a module, optionally with conditions and subpath exports. @@ -233,14 +236,13 @@ declare namespace PackageJson { | null | string | Array - | ExportConditions - | {[path: string]: Exports}; + | ExportConditions; /** - Import map entries of a module, optionally with conditions. + Import map entries of a module, optionally with conditions and subpath imports. */ export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style - [key: `#${string}`]: string | {[key in ExportCondition]?: Exports}; + [key: `#${string}`]: Exports; }; // eslint-disable-next-line @typescript-eslint/consistent-type-definitions diff --git a/test-d/package-json.ts b/test-d/package-json.ts index 16b21b987..95054cf40 100644 --- a/test-d/package-json.ts +++ b/test-d/package-json.ts @@ -57,9 +57,19 @@ expectAssignable({'#unicorn': 'unicorn'}); expectAssignable({ '#unicorn': { import: {browser: 'unicorn', node: 'pony'}, + require: ['./fallback-1', './fallback-2', {default: './fallback-3', browser: null}], + custom: null, default: 'horse', }, }); +expectAssignable({ + './unicorn': { + import: {browser: './unicorn.js', node: './pony.js'}, + require: ['./fallback-1', './fallback-2', {default: './fallback-3', browser: null}], + custom: null, + default: './horse.js', + }, +}); expectNotAssignable({unicorn: 'unicorn'}); expectType(packageJson.preferGlobal); expectType(packageJson.private);