Skip to content

Commit

Permalink
Actually have a chance to reuse optional property signatures in the n…
Browse files Browse the repository at this point in the history
…ode builder (#57995)
  • Loading branch information
weswigham authored Mar 29, 2024
1 parent 278b4f9 commit b0042a7
Show file tree
Hide file tree
Showing 71 changed files with 335 additions and 335 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8551,7 +8551,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (typeFromTypeNode === type) {
return true;
}
if (annotatedDeclaration && (isParameter(annotatedDeclaration) || isPropertyDeclaration(annotatedDeclaration)) && annotatedDeclaration.questionToken) {
if (annotatedDeclaration && (isParameter(annotatedDeclaration) || isPropertySignature(annotatedDeclaration) || isPropertyDeclaration(annotatedDeclaration)) && annotatedDeclaration.questionToken) {
return getTypeWithFacts(type, TypeFacts.NEUndefined) === typeFromTypeNode;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ declare const foo: ["a", string, number] | ["b", string, boolean];
export function test(arg: { index?: number }) {
>test : (arg: { index?: number; }) => void
> : ^^^^^^ ^^^^^^^^^
>arg : { index?: number | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arg : { index?: number; }
> : ^^^^^^^^^^ ^^^
>index : number | undefined
> : ^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ declare class Component<P> {
class C<T> extends Component<{ x?: boolean; } & T> {}
>C : C<T>
> : ^^^^
>Component : Component<{ x?: boolean | undefined; } & T>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Component : Component<{ x?: boolean; } & T>
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^
>x : boolean | undefined
> : ^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ declare class Component<P> {
> : ^^^

readonly props: Readonly<P> & Readonly<{ children?: {} }>;
>props : Readonly<P> & Readonly<{ children?: {} | undefined; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>props : Readonly<P> & Readonly<{ children?: {}; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^
>children : {} | undefined
> : ^^^^^^^^^^^^^^
}
Expand All @@ -42,8 +42,8 @@ interface ComponentClass<P = {}> {
}
interface FunctionComponent<P = {}> {
(props: P & { children?: {} }, context?: any): {} | null;
>props : P & { children?: {} | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>props : P & { children?: {}; }
> : ^^^^^^^^^^^^^^^^^ ^^^
>children : {} | undefined
> : ^^^^^^^^^^^^^^
>context : any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ declare function createMachine<
TTypesMeta extends TypegenEnabled | TypegenDisabled = TypegenDisabled
>(
config: {
>config : { types?: TTypesMeta | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>config : { types?: TTypesMeta; }
> : ^^^^^^^^^^ ^^^

types?: TTypesMeta;
>types : TTypesMeta | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ declare function match<T>(cb: (value: T) => boolean): T;
declare function foo(pos: { x?: number; y?: number }): boolean;
>foo : (pos: { x?: number; y?: number; }) => boolean
> : ^^^^^^ ^^^^^
>pos : { x?: number | undefined; y?: number | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>pos : { x?: number; y?: number; }
> : ^^^^^^ ^^^^^^ ^^^
>x : number | undefined
> : ^^^^^^^^^^^^^^^^^^
>y : number | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ declare function id3<T extends (x: { foo: any }) => any>(input: T): T;
declare function id4<T extends (x: { foo?: number }) => any>(input: T): T;
>id4 : <T extends (x: { foo?: number; }) => any>(input: T) => T
> : ^ ^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^ ^^^^^
>x : { foo?: number | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>x : { foo?: number; }
> : ^^^^^^^^ ^^^
>foo : number | undefined
> : ^^^^^^^^^^^^^^^^^^
>input : T
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/controlFlowAliasing.types
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,8 @@ class C11 {
function f40(obj: { kind: 'foo', foo?: string } | { kind: 'bar', bar?: number }) {
>f40 : (obj: { kind: 'foo'; foo?: string; } | { kind: 'bar'; bar?: number; }) => void
> : ^^^^^^ ^^^^^^^^^
>obj : { kind: 'foo'; foo?: string | undefined; } | { kind: 'bar'; bar?: number | undefined; }
> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj : { kind: 'foo'; foo?: string; } | { kind: 'bar'; bar?: number; }
> : ^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^ ^^^
>kind : "foo"
> : ^^^^^
>foo : string | undefined
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/controlFlowDeleteOperator.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function f() {
> : ^^^^^^^^^^

let x: { a?: number | string, b: number | string } = { b: 1 };
>x : { a?: string | number | undefined; b: number | string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>x : { a?: number | string; b: number | string; }
> : ^^^^^^ ^^^^^ ^^^
>a : string | number | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>b : string | number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== controlFlowInitializedDestructuringVariables.ts ===
declare const obj: { a?: string, b?: number };
>obj : { a?: string | undefined; b?: number | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj : { a?: string; b?: number; }
> : ^^^^^^ ^^^^^^ ^^^
>a : string | undefined
> : ^^^^^^^^^^^^^^^^^^
>b : number | undefined
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/controlFlowOptionalChain.types
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ o3.x;
> : ^^^^^

declare const o4: { x?: { y: boolean } };
>o4 : { x?: { y: boolean; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>o4 : { x?: { y: boolean; }; }
> : ^^^^^^ ^^^
>x : { y: boolean; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>y : boolean
Expand Down Expand Up @@ -504,12 +504,12 @@ o4.x.y;
> : ^^^^^^^

declare const o5: { x?: { y: { z?: { w: boolean } } } };
>o5 : { x?: { y: { z?: { w: boolean; }; }; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>o5 : { x?: { y: { z?: { w: boolean; }; }; }; }
> : ^^^^^^ ^^^
>x : { y: { z?: { w: boolean; }; }; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>y : { z?: { w: boolean; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>y : { z?: { w: boolean; }; }
> : ^^^^^^ ^^^
>z : { w: boolean; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>w : boolean
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/controlFlowOptionalChain3.types
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function Test3({ foo }: { foo: Foo | undefined }) {
function test4(options?: { a?: boolean; b?: boolean }) {
>test4 : (options?: { a?: boolean; b?: boolean; }) => void
> : ^^^^^^^^^^^ ^^^^^^^^^
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>options : { a?: boolean; b?: boolean; } | undefined
> : ^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^
>a : boolean | undefined
> : ^^^^^^^^^^^^^^^^^^^
>b : boolean | undefined
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/correlatedUnions.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ declare function processEvents<K extends keyof DocumentEventMap>(events: Ev<K>[]
declare function createEventListener<K extends keyof DocumentEventMap>({ name, once, callback }: Ev<K>): Ev<K>;
declare const clickEvent: {
readonly name: "click";
readonly once?: boolean | undefined;
readonly once?: boolean;
readonly callback: (ev: MouseEvent) => void;
};
declare const scrollEvent: {
readonly name: "scroll";
readonly once?: boolean | undefined;
readonly once?: boolean;
readonly callback: (ev: Event) => void;
};
declare function ff1(): void;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/declarationEmitOptionalMethod.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const Foo = (opts: {
> : ^^^^^^^ ^^^^^
>(opts: { a?(): void, b?: () => void,}): { c?(): void, d?: () => void,} => ({ }) : (opts: { a?(): void; b?: () => void; }) => { c?(): void; d?: () => void; }
> : ^^^^^^^ ^^^^^
>opts : { a?(): void; b?: (() => void) | undefined; }
> : ^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
>opts : { a?(): void; b?: () => void; }
> : ^^^^^^^^ ^^^^^^ ^^^

a?(): void,
>a : (() => void) | undefined
Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/deleteChain.types
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ delete (o3.b?.c);
> : ^^^^^^^^^^^^^^^^^^

declare const o4: { b?: { c: { d?: { e: string } } } };
>o4 : { b?: { c: { d?: { e: string; }; }; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>o4 : { b?: { c: { d?: { e: string; }; }; }; }
> : ^^^^^^ ^^^
>b : { c: { d?: { e: string; }; }; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>c : { d?: { e: string; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>c : { d?: { e: string; }; }
> : ^^^^^^ ^^^
>d : { e: string; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>e : string
Expand Down Expand Up @@ -192,8 +192,8 @@ declare const o5: { b?(): { c: { d?: { e: string } } } };
> : ^^^^^^^^ ^^^
>b : (() => { c: { d?: { e: string; }; }; }) | undefined
> : ^^^^^^^ ^^^^^^^^^^^^^
>c : { d?: { e: string; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>c : { d?: { e: string; }; }
> : ^^^^^^ ^^^
>d : { e: string; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>e : string
Expand Down Expand Up @@ -250,12 +250,12 @@ delete (o5.b?.().c.d?.e);
> : ^^^^^^^^^^^^^^^^^^

declare const o6: { b?: { c: { d?: { e: string } } } };
>o6 : { b?: { c: { d?: { e: string; }; }; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>o6 : { b?: { c: { d?: { e: string; }; }; }; }
> : ^^^^^^ ^^^
>b : { c: { d?: { e: string; }; }; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>c : { d?: { e: string; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>c : { d?: { e: string; }; }
> : ^^^^^^ ^^^
>d : { e: string; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>e : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== destructuringAssignmentWithDefault.ts ===
const a: { x?: number } = { };
>a : { x?: number | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>a : { x?: number; }
> : ^^^^^^ ^^^
>x : number | undefined
> : ^^^^^^^^^^^^^^^^^^
>{ } : {}
Expand Down Expand Up @@ -34,8 +34,8 @@ let x = 0;
function f1(options?: { color?: string, width?: number }) {
>f1 : (options?: { color?: string; width?: number; }) => void
> : ^^^^^^^^^^^ ^^^^^^^^^
>options : { color?: string | undefined; width?: number | undefined; } | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>options : { color?: string; width?: number; } | undefined
> : ^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^
>color : string | undefined
> : ^^^^^^^^^^^^^^^^^^
>width : number | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== destructuringAssignmentWithDefault2.ts ===
const a: { x?: number; y?: number } = { };
>a : { x?: number | undefined; y?: number | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>a : { x?: number; y?: number; }
> : ^^^^^^ ^^^^^^ ^^^
>x : number | undefined
> : ^^^^^^^^^^^^^^^^^^
>y : number | undefined
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/destructuringControlFlow.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
function f1(obj: { a?: string }) {
>f1 : (obj: { a?: string; }) => void
> : ^^^^^^ ^^^^^^^^^
>obj : { a?: string | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj : { a?: string; }
> : ^^^^^^ ^^^
>a : string | undefined
> : ^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -158,8 +158,8 @@ function f2(obj: [number, string] | null[]) {
function f3(obj: { a?: number, b?: string }) {
>f3 : (obj: { a?: number; b?: string; }) => void
> : ^^^^^^ ^^^^^^^^^
>obj : { a?: number | undefined; b?: string | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj : { a?: number; b?: string; }
> : ^^^^^^ ^^^^^^ ^^^
>a : number | undefined
> : ^^^^^^^^^^^^^^^^^^
>b : string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
function bar(props: { x?: string; y?: string }) {
>bar : (props: { x?: string; y?: string; }) => { [x: string]: number; }
> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>props : { x?: string | undefined; y?: string | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>props : { x?: string; y?: string; }
> : ^^^^^^ ^^^^^^ ^^^
>x : string | undefined
> : ^^^^^^^^^^^^^^^^^^
>y : string | undefined
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/elementAccessChain.types
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ o3.b?.["c"];
> : ^^^

declare const o4: { b?: { c: { d?: { e: string } } } };
>o4 : { b?: { c: { d?: { e: string; }; }; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>o4 : { b?: { c: { d?: { e: string; }; }; }; }
> : ^^^^^^ ^^^
>b : { c: { d?: { e: string; }; }; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>c : { d?: { e: string; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>c : { d?: { e: string; }; }
> : ^^^^^^ ^^^
>d : { e: string; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>e : string
Expand Down Expand Up @@ -136,8 +136,8 @@ declare const o5: { b?(): { c: { d?: { e: string } } } };
> : ^^^^^^^^ ^^^
>b : (() => { c: { d?: { e: string; }; }; }) | undefined
> : ^^^^^^^ ^^^^^^^^^^^^^
>c : { d?: { e: string; } | undefined; }
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
>c : { d?: { e: string; }; }
> : ^^^^^^ ^^^
>d : { e: string; } | undefined
> : ^^^^^ ^^^^^^^^^^^^^^^
>e : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function f<TType>(
> : ^ ^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^

a: { weak?: string } & Readonly<TType> & { name: "ok" },
>a : { weak?: string | undefined; } & Readonly<TType> & { name: "ok"; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>a : { weak?: string; } & Readonly<TType> & { name: "ok"; }
> : ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>weak : string | undefined
> : ^^^^^^^^^^^^^^^^^^
>name : "ok"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1492,8 +1492,8 @@ function f12(x: { a: string }) {
function f13(x: { a?: string }) {
>f13 : (x: { a?: string; }) => void
> : ^^^^ ^^^^^^^^^
>x : { a?: string | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>x : { a?: string; }
> : ^^^^^^ ^^^
>a : string | undefined
> : ^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/indexSignatures1.types
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,8 @@ const directive = Symbol('directive');
declare function foo<TArg, TRet, TDir>(options: { [x in string]: (arg: TArg) => TRet } & { [directive]?: TDir }): void;
>foo : <TArg, TRet, TDir>(options: { [x in string]: (arg: TArg) => TRet; } & { [directive]?: TDir; }) => void
> : ^ ^^ ^^ ^^^^^^^^^^^ ^^^^^
>options : { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>options : { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir; }
> : ^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^
>arg : TArg
> : ^^^^
>[directive] : TDir | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ declare const x2: { a: string, b: number | undefined };
> : ^^^^^^^^^^^^^^^^^^

declare const x3: { a: string, b?: number };
>x3 : { a: string; b?: number | undefined; }
> : ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>x3 : { a: string; b?: number; }
> : ^^^^^ ^^^^^^ ^^^
>a : string
> : ^^^^^^
>b : number | undefined
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/instantiateContextualTypes.types
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ interface ComponentClass<P = {}> {
}

type CreateElementChildren<P> =
>CreateElementChildren : P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>CreateElementChildren : P extends { children?: infer C; } ? C extends any[] ? C : C[] : unknown
> : ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

P extends { children?: infer C }
>children : C | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
=== intersectionOfTypeVariableHasApparentSignatures.ts ===
interface Component<P> {
props: Readonly<P> & Readonly<{ children?: {} }>;
>props : Readonly<P> & Readonly<{ children?: {} | undefined; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>props : Readonly<P> & Readonly<{ children?: {}; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^
>children : {} | undefined
> : ^^^^^^^^^^^^^^
}
Expand Down
Loading

0 comments on commit b0042a7

Please sign in to comment.