Skip to content

Commit

Permalink
PackageJson: Disallow undefined in exports (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed May 30, 2023
1 parent 6a82900 commit dc38b70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
20 changes: 3 additions & 17 deletions source/package-json.d.ts
Expand Up @@ -208,26 +208,12 @@ declare namespace PackageJson {
*/
export type Dependency = Partial<Record<string, string>>;

/**
Conditions which provide a way to resolve a package entry point based on the environment.
*/
export type ExportCondition = LiteralUnion<
| 'import'
| 'require'
| 'node'
| 'node-addons'
| 'deno'
| 'browser'
| 'electron'
| 'react-native'
| 'default',
string
>;

/**
A mapping of conditions and the paths to which they resolve.
*/
type ExportConditions = {[condition in ExportCondition]?: Exports};
type ExportConditions = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
[condition: string]: Exports;
};

/**
Entry points of a module, optionally with conditions and subpath exports.
Expand Down
3 changes: 3 additions & 0 deletions test-d/package-json.ts
Expand Up @@ -70,6 +70,9 @@ expectAssignable<PackageJson.Exports>({
default: './horse.js',
},
});
expectNotAssignable<PackageJson.Exports>({
'./unicorn': undefined,
});
expectNotAssignable<PackageJson.Imports>({unicorn: 'unicorn'});
expectType<boolean | undefined>(packageJson.preferGlobal);
expectType<boolean | undefined>(packageJson.private);
Expand Down

0 comments on commit dc38b70

Please sign in to comment.