Skip to content

Commit

Permalink
Fix support for exactOptionalPropertyTypes: true tsconfig (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiyaaaaa authored Jan 24, 2024
1 parent 18a12b7 commit a54e313
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"node": ">=16"
},
"scripts": {
"test": "xo && tsd && tsc && npm run test:undefined-on-partial-deep && node script/test/source-files-extension.js",
"test:undefined-on-partial-deep": "cd test-d/undefined-on-partial-deep && tsc --project tsconfig.json"
"test": "xo && tsd && tsc && node script/test/source-files-extension.js"
},
"files": [
"index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion source/merge-deep.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
UnknownArrayOrTuple,
} from './internal';
import type {UnknownRecord} from './unknown-record';
import type {EnforceOptional} from './enforce-optional';

/**
Deeply simplifies an object excluding iterables and functions. Used internally to improve the UX and accept both interfaces and type aliases as inputs.
Expand Down Expand Up @@ -289,7 +290,7 @@ type MergeDeepOrReturn<
: DefaultType
: Destination extends UnknownArrayOrTuple
? Source extends UnknownArrayOrTuple
? MergeDeepArrayOrTuple<Destination, Source, Merge<Options, {spreadTopLevelArrays: false}>>
? MergeDeepArrayOrTuple<Destination, Source, EnforceOptional<Merge<Options, {spreadTopLevelArrays: false}>>>
: DefaultType
: DefaultType>;

Expand Down
7 changes: 4 additions & 3 deletions test-d/conditional-pick-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface InterfaceA {

type Example = {
optional?: boolean;
optionalWithUndefined?: boolean | undefined;
literal: 'foo';
string: string;
map: Map<string, string>;
Expand Down Expand Up @@ -73,17 +74,17 @@ expectType<{
object: {
string: string;
subObject: {
optional?: string | undefined;
optional?: string;
string: string;
};
};
}>(stringPickOptional);

declare const stringPickOptionalOnly: ConditionalPickDeep<Example, string | undefined, {condition: 'equality'}>;
expectType<{object: {subObject: {optional?: string | undefined}}}>(stringPickOptionalOnly);
expectType<{object: {subObject: {optional?: string}}}>(stringPickOptionalOnly);

declare const booleanPick: ConditionalPickDeep<Example, boolean | undefined>;
expectType<{optional?: boolean | undefined}>(booleanPick);
expectType<{optional?: boolean; optionalWithUndefined?: boolean | undefined}>(booleanPick);

declare const numberPick: ConditionalPickDeep<Example, number>;
expectType<{number: 1; interface: {a: number}}>(numberPick);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
@note This file is used for testing by `tsc` but not `tsd`, so we can just test assignable.
*/
// TODO: Test equality
import {expectAssignable} from 'tsd';
import type {UndefinedOnPartialDeep} from '../../source/undefined-on-partial-deep';
import type {UndefinedOnPartialDeep} from '../source/undefined-on-partial-deep';

type TestType1 = UndefinedOnPartialDeep<{required: string; optional?: string; optional2?: number; optional3?: string}>;
expectAssignable<TestType1>({required: '', optional: undefined, optional2: 1});
Expand Down
7 changes: 0 additions & 7 deletions test-d/undefined-on-partial-deep/tsconfig.json

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ES2020",
"DOM"
],
"exactOptionalPropertyTypes": true,
"skipLibCheck": false, // Ensures .d.ts files are checked: https://github.com/sindresorhus/tsconfig/issues/15
},
"exclude": [
Expand Down

0 comments on commit a54e313

Please sign in to comment.