Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PackageJson): disallow undefined in exports #626

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions source/package-json.d.ts
Original file line number Diff line number Diff line change
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
>;
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can no longer use ExportCondition as the key type. However, the only requirement for an export condition is that it should be a string.

Keeping a list of common export conditions will only add to the maintenance workload, and provide little value for autocompletion, so I suggest removing it.


/**
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
Original file line number Diff line number Diff line change
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