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 deep properties of PackageJson and TsConfigJson #269

Merged
merged 3 commits into from May 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions source/package-json.d.ts
Expand Up @@ -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<string, string>;
} & Partial<Record<string, string>>;

/**
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<string, string>;
export type Dependency = Partial<Record<string, string>>;

/**
Conditions which provide a way to resolve a package entry point based on the environment.
Expand Down Expand Up @@ -262,7 +262,7 @@ declare namespace PackageJson {
*/
browser?:
| string
| Record<string, string | false>;
| Partial<Record<string, string | false>>;

/**
Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
Expand All @@ -281,7 +281,7 @@ declare namespace PackageJson {
/**
Version selection map of TypeScript.
*/
typesVersions?: Record<string, Record<string, string[]>>;
typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;

/**
Location of the bundled TypeScript declaration file. Alias of `types`.
Expand Down Expand Up @@ -442,7 +442,7 @@ declare namespace PackageJson {
*/
bin?:
| string
| Record<string, string>;
| Partial<Record<string, string>>;

/**
Filenames to put in place for the `man` program to find.
Expand Down Expand Up @@ -504,7 +504,7 @@ declare namespace PackageJson {
/**
Indicate peer dependencies that are optional.
*/
peerDependenciesMeta?: Record<string, {optional: true}>;
peerDependenciesMeta?: Partial<Record<string, {optional: true}>>;

/**
Package names that are bundled when the package is published.
Expand All @@ -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;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion source/tsconfig-json.d.ts
Expand Up @@ -713,7 +713,7 @@ declare namespace TsConfigJson {
/**
Specify path mapping to be computed relative to baseUrl option.
*/
paths?: Record<string, string[]>;
paths?: Partial<Record<string, string[]>>;
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Why is this changed?

VSCode doesn't allow undefined to be set:
Screen Shot 2022-06-07 at 5 00 50 PM

tsc requires a non-empty array value:

Screen Shot 2022-06-07 at 5 01 49 PM

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Revert PR: #404


/**
List of TypeScript language server plugins to load.
Expand Down
17 changes: 15 additions & 2 deletions test-d/package-json.ts
Expand Up @@ -16,7 +16,7 @@ expectType<PackageJson.Person[] | undefined>(packageJson.contributors);
expectType<PackageJson.Person[] | undefined>(packageJson.maintainers);
expectType<string[] | undefined>(packageJson.files);
expectType<string | undefined>(packageJson.main);
expectType<string | Record<string, string> | undefined>(packageJson.bin);
expectType<string | Partial<Record<string, string>> | undefined>(packageJson.bin);
expectType<string | undefined>(packageJson.types);
expectType<string | undefined>(packageJson.typings);
expectType<string | string[] | undefined>(packageJson.man);
Expand All @@ -36,7 +36,7 @@ expectType<string[] | undefined>(packageJson.bundleDependencies);
expectType<string[] | undefined>(packageJson.bundledDependencies);
expectType<PackageJson.Dependency | undefined>(packageJson.resolutions);
expectType<PackageJson.WorkspaceConfig | string[] | undefined>(packageJson.workspaces);
expectType<Record<string, string> | undefined>(packageJson.engines);
expectType<Partial<Record<string, string>> | undefined>(packageJson.engines);
expectType<boolean | undefined>(packageJson.engineStrict);
expectAssignable<
| undefined
Expand Down Expand Up @@ -67,4 +67,17 @@ expectType<
>(packageJson.esnext);
expectType<PackageJson | undefined>(packageJson.jspm);

// Undefined assigns
expectAssignable<PackageJson.Dependency>({dep: undefined});
expectAssignable<typeof packageJson['engines']>({engine: undefined});
expectAssignable<typeof packageJson['scripts']>({unknownScript: undefined});
expectAssignable<typeof packageJson['bin']>({bin: undefined});
expectAssignable<typeof packageJson['typesVersions']>({
'>=4': {
'*': ['src'],
somethingElse: undefined,
},
'<4': undefined,
});

expectNotAssignable<Record<string, unknown>>(packageJson);
5 changes: 4 additions & 1 deletion 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 = {};
Expand All @@ -11,3 +11,6 @@ expectType<string[] | undefined>(tsConfig.files);
expectType<string[] | undefined>(tsConfig.include);
expectType<TsConfigJson.References[] | undefined>(tsConfig.references);
expectType<TsConfigJson.TypeAcquisition | undefined>(tsConfig.typeAcquisition);

// Undefined assigns
expectAssignable<NonNullable<typeof tsConfig['compilerOptions']>['paths']>({path: undefined});