Skip to content
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17776,7 +17776,7 @@ func (c *Checker) addOptionalityEx(t *Type, isProperty bool, isOptional bool) *T
}

func (c *Checker) getOptionalType(t *Type, isProperty bool) *Type {
// debug.Assert(c.strictNullChecks) // TODO: fix bug in isRequiredInitializedParameter
debug.Assert(c.strictNullChecks)
missingOrUndefined := core.IfElse(isProperty, c.undefinedOrMissingType, c.undefinedType)
if t == missingOrUndefined || t.flags&TypeFlagsUnion != 0 && t.Types()[0] == missingOrUndefined {
return t
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func (r *emitResolver) isOptionalUninitializedParameterProperty(parameter *ast.N
}

func (r *emitResolver) isRequiredInitializedParameter(parameter *ast.Node, enclosingDeclaration *ast.Node) bool {
if r.checker.strictNullChecks || r.isOptionalParameter(parameter) || /*isJSDocParameterTag(parameter) ||*/ parameter.Initializer() == nil { // !!! TODO: JSDoc Support
if !r.checker.strictNullChecks || r.isOptionalParameter(parameter) || /*isJSDocParameterTag(parameter) ||*/ parameter.Initializer() == nil { // !!! TODO: JSDoc Support
return false
}
if ast.HasSyntacticModifier(parameter, ast.ModifierFlagsParameterPropertyModifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function fnWithPartialAnnotationOnDefaultparam(x: P = null! as P, b: numb


//// [declarationEmitCastReusesTypeNode1.d.ts]
type P = {} & {
name: string;
};
export declare let vLet: {
name: string;
};
Expand Down Expand Up @@ -77,6 +80,4 @@ declare const _default: {
};
export default _default;
// allows `undefined` on the input side, thanks to the initializer
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name: string;
}, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
--- old.declarationEmitCastReusesTypeNode1(strictnullchecks=false).js
+++ new.declarationEmitCastReusesTypeNode1(strictnullchecks=false).js
@@= skipped -30, +30 lines =@@


//// [declarationEmitCastReusesTypeNode1.d.ts]
-type P = {} & {
- name: string;
-};
@@= skipped -33, +33 lines =@@
type P = {} & {
name: string;
};
-export declare let vLet: P;
-export declare const vConst: P;
-export declare function fn(p?: P): void;
Expand Down Expand Up @@ -66,8 +63,5 @@
+ name: string;
+};
export default _default;
-export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
+// allows `undefined` on the input side, thanks to the initializer
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
+ name: string;
+}, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export function fnWithPartialAnnotationOnDefaultparam(x: P = null! as P, b: numb


//// [declarationEmitCastReusesTypeNode1.d.ts]
type P = {} & {
name: string;
};
export declare let vLet: {
name: string;
};
Expand All @@ -45,7 +42,7 @@ export declare function fn(p?: {
}): void;
export declare function fnWithRequiredDefaultParam(p: {
name: string;
}, req: number): void;
} | undefined, req: number): void;
export declare class C {
ctorField: {
name: string;
Expand All @@ -64,7 +61,7 @@ export declare class C {
}): void;
methodWithRequiredDefault(p: {
name: string;
}, req: number): void;
} | undefined, req: number): void;
constructor(ctorField?: {
name: string;
});
Expand All @@ -80,4 +77,6 @@ declare const _default: {
};
export default _default;
// allows `undefined` on the input side, thanks to the initializer
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name: string;
} | undefined, b: number): void;
Comment on lines +80 to +82
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that we are losing P here; I assume this is a reuse problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep - we just swapped the diff caused by lacking node reuse logic from the strict: false case to strict: true.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
--- old.declarationEmitCastReusesTypeNode1(strictnullchecks=true).js
+++ new.declarationEmitCastReusesTypeNode1(strictnullchecks=true).js
@@= skipped -33, +33 lines =@@
type P = {} & {
name: string;
};
@@= skipped -30, +30 lines =@@


//// [declarationEmitCastReusesTypeNode1.d.ts]
-type P = {} & {
- name: string;
-};
-export declare let vLet: P;
-export declare const vConst: P;
-export declare function fn(p?: P): void;
Expand All @@ -19,7 +22,7 @@
+}): void;
+export declare function fnWithRequiredDefaultParam(p: {
+ name: string;
+}, req: number): void;
+} | undefined, req: number): void;
export declare class C {
- ctorField: P;
- field: P;
Expand Down Expand Up @@ -47,7 +50,7 @@
+ }): void;
+ methodWithRequiredDefault(p: {
+ name: string;
+ }, req: number): void;
+ } | undefined, req: number): void;
+ constructor(ctorField?: {
+ name: string;
+ });
Expand All @@ -65,4 +68,6 @@
export default _default;
-export declare function fnWithPartialAnnotationOnDefaultparam(x: P | undefined, b: number): void;
+// allows `undefined` on the input side, thanks to the initializer
+export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
+ name: string;
+} | undefined, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ declare const _default: {
};
export default _default;
// allows `undefined` on the input side, thanks to the initializer
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
name: string;
}, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
name: string;
};
export default _default;
-export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
+// allows `undefined` on the input side, thanks to the initializer
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
name: string;
}, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export declare function fn(p?: {
}): void;
export declare function fnWithRequiredDefaultParam(p: {
name: string;
}, req: number): void;
} | undefined, req: number): void;
export declare class C {
ctorField: {
name: string;
Expand All @@ -59,7 +59,7 @@ export declare class C {
}): void;
methodWithRequiredDefault(p: {
name: string;
}, req: number): void;
} | undefined, req: number): void;
constructor(ctorField?: {
name: string;
});
Expand All @@ -75,6 +75,6 @@ declare const _default: {
};
export default _default;
// allows `undefined` on the input side, thanks to the initializer
export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name: string;
}, b: number): void;
} | undefined, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
+export declare function fnWithRequiredDefaultParam(p: {
name: string;
-}) | undefined, req: number): void;
+}, req: number): void;
+} | undefined, req: number): void;
export declare class C {
- ctorField: {} & {
- name: string;
Expand Down Expand Up @@ -59,7 +59,7 @@
name: string;
- }) | undefined, req: number): void;
- constructor(ctorField?: {} & {
+ }, req: number): void;
+ } | undefined, req: number): void;
+ constructor(ctorField?: {
name: string;
});
Expand All @@ -79,7 +79,7 @@
export default _default;
-export declare function fnWithPartialAnnotationOnDefaultparam(x: ({} & {
+// allows `undefined` on the input side, thanks to the initializer
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name: string;
-}) | undefined, b: number): void;
+}, b: number): void;
+} | undefined, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function fnWithPartialAnnotationOnDefaultparam(x: P = <P>null!, b: number


//// [declarationEmitCastReusesTypeNode3.d.ts]
type P = {} & {
name: string;
};
export declare let vLet: {
name: string;
};
Expand Down Expand Up @@ -77,6 +80,4 @@ declare const _default: {
};
export default _default;
// allows `undefined` on the input side, thanks to the initializer
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name: string;
}, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
--- old.declarationEmitCastReusesTypeNode3(strictnullchecks=false).js
+++ new.declarationEmitCastReusesTypeNode3(strictnullchecks=false).js
@@= skipped -30, +30 lines =@@


//// [declarationEmitCastReusesTypeNode3.d.ts]
-type P = {} & {
- name: string;
-};
@@= skipped -33, +33 lines =@@
type P = {} & {
name: string;
};
-export declare let vLet: P;
-export declare const vConst: P;
-export declare function fn(p?: P): void;
Expand Down Expand Up @@ -66,8 +63,5 @@
+ name: string;
+};
export default _default;
-export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
+// allows `undefined` on the input side, thanks to the initializer
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
+ name: string;
+}, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export function fnWithPartialAnnotationOnDefaultparam(x: P = <P>null!, b: number


//// [declarationEmitCastReusesTypeNode3.d.ts]
type P = {} & {
name: string;
};
export declare let vLet: {
name: string;
};
Expand All @@ -45,7 +42,7 @@ export declare function fn(p?: {
}): void;
export declare function fnWithRequiredDefaultParam(p: {
name: string;
}, req: number): void;
} | undefined, req: number): void;
export declare class C {
ctorField: {
name: string;
Expand All @@ -64,7 +61,7 @@ export declare class C {
}): void;
methodWithRequiredDefault(p: {
name: string;
}, req: number): void;
} | undefined, req: number): void;
constructor(ctorField?: {
name: string;
});
Expand All @@ -80,4 +77,6 @@ declare const _default: {
};
export default _default;
// allows `undefined` on the input side, thanks to the initializer
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name: string;
} | undefined, b: number): void;
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
--- old.declarationEmitCastReusesTypeNode3(strictnullchecks=true).js
+++ new.declarationEmitCastReusesTypeNode3(strictnullchecks=true).js
@@= skipped -33, +33 lines =@@
type P = {} & {
name: string;
};
@@= skipped -30, +30 lines =@@


//// [declarationEmitCastReusesTypeNode3.d.ts]
-type P = {} & {
- name: string;
-};
-export declare let vLet: P;
-export declare const vConst: P;
-export declare function fn(p?: P): void;
Expand All @@ -19,7 +22,7 @@
+}): void;
+export declare function fnWithRequiredDefaultParam(p: {
+ name: string;
+}, req: number): void;
+} | undefined, req: number): void;
export declare class C {
- ctorField: P;
- field: P;
Expand Down Expand Up @@ -47,7 +50,7 @@
+ }): void;
+ methodWithRequiredDefault(p: {
+ name: string;
+ }, req: number): void;
+ } | undefined, req: number): void;
+ constructor(ctorField?: {
+ name: string;
+ });
Expand All @@ -65,4 +68,6 @@
export default _default;
-export declare function fnWithPartialAnnotationOnDefaultparam(x: P | undefined, b: number): void;
+// allows `undefined` on the input side, thanks to the initializer
+export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
+ name: string;
+} | undefined, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,4 @@ export default /** @type {P} */ _default;
* @param {P} x
* @param {number} b
*/
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name?: string;
}, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
-declare const _default: P;
-export default _default;
-export type P = {} & {
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name?: string;
- name?: string;
-};
+}, b: number): void;
+export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export declare function fn(p?: {
/** @param {number} req */
export declare function fnWithRequiredDefaultParam(p: {
name?: string | undefined;
}, req: number): void;
} | undefined, req: number): void;
export declare class C {
field: {
name?: string | undefined;
Expand All @@ -74,7 +74,7 @@ export declare class C {
/** @param {number} req */
methodWithRequiredDefault(p: {
name?: string | undefined;
}, req: number): void;
} | undefined, req: number): void;
constructor(ctorField?: {
name?: string | undefined;
});
Expand All @@ -95,4 +95,6 @@ export default /** @type {P} */ _default;
* @param {P} x
* @param {number} b
*/
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
name?: string | undefined;
} | undefined, b: number): void;
Loading
Loading