Skip to content

Commit 4ddea0c

Browse files
authored
Fix typo in isRequiredInitializedParameter (#1598)
1 parent 7f19f5b commit 4ddea0c

24 files changed

+88
-109
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17776,7 +17776,7 @@ func (c *Checker) addOptionalityEx(t *Type, isProperty bool, isOptional bool) *T
1777617776
}
1777717777

1777817778
func (c *Checker) getOptionalType(t *Type, isProperty bool) *Type {
17779-
// debug.Assert(c.strictNullChecks) // TODO: fix bug in isRequiredInitializedParameter
17779+
debug.Assert(c.strictNullChecks)
1778017780
missingOrUndefined := core.IfElse(isProperty, c.undefinedOrMissingType, c.undefinedType)
1778117781
if t == missingOrUndefined || t.flags&TypeFlagsUnion != 0 && t.Types()[0] == missingOrUndefined {
1778217782
return t

internal/checker/emitresolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ func (r *emitResolver) isOptionalUninitializedParameterProperty(parameter *ast.N
552552
}
553553

554554
func (r *emitResolver) isRequiredInitializedParameter(parameter *ast.Node, enclosingDeclaration *ast.Node) bool {
555-
if r.checker.strictNullChecks || r.isOptionalParameter(parameter) || /*isJSDocParameterTag(parameter) ||*/ parameter.Initializer() == nil { // !!! TODO: JSDoc Support
555+
if !r.checker.strictNullChecks || r.isOptionalParameter(parameter) || /*isJSDocParameterTag(parameter) ||*/ parameter.Initializer() == nil { // !!! TODO: JSDoc Support
556556
return false
557557
}
558558
if ast.HasSyntacticModifier(parameter, ast.ModifierFlagsParameterPropertyModifier) {

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode1(strictnullchecks=false).js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export function fnWithPartialAnnotationOnDefaultparam(x: P = null! as P, b: numb
3131

3232

3333
//// [declarationEmitCastReusesTypeNode1.d.ts]
34+
type P = {} & {
35+
name: string;
36+
};
3437
export declare let vLet: {
3538
name: string;
3639
};
@@ -77,6 +80,4 @@ declare const _default: {
7780
};
7881
export default _default;
7982
// allows `undefined` on the input side, thanks to the initializer
80-
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
81-
name: string;
82-
}, b: number): void;
83+
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode1(strictnullchecks=false).js.diff

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
--- old.declarationEmitCastReusesTypeNode1(strictnullchecks=false).js
22
+++ new.declarationEmitCastReusesTypeNode1(strictnullchecks=false).js
3-
@@= skipped -30, +30 lines =@@
4-
5-
6-
//// [declarationEmitCastReusesTypeNode1.d.ts]
7-
-type P = {} & {
8-
- name: string;
9-
-};
3+
@@= skipped -33, +33 lines =@@
4+
type P = {} & {
5+
name: string;
6+
};
107
-export declare let vLet: P;
118
-export declare const vConst: P;
129
-export declare function fn(p?: P): void;
@@ -66,8 +63,5 @@
6663
+ name: string;
6764
+};
6865
export default _default;
69-
-export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
7066
+// allows `undefined` on the input side, thanks to the initializer
71-
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
72-
+ name: string;
73-
+}, b: number): void;
67+
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode1(strictnullchecks=true).js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ export function fnWithPartialAnnotationOnDefaultparam(x: P = null! as P, b: numb
3131

3232

3333
//// [declarationEmitCastReusesTypeNode1.d.ts]
34-
type P = {} & {
35-
name: string;
36-
};
3734
export declare let vLet: {
3835
name: string;
3936
};
@@ -45,7 +42,7 @@ export declare function fn(p?: {
4542
}): void;
4643
export declare function fnWithRequiredDefaultParam(p: {
4744
name: string;
48-
}, req: number): void;
45+
} | undefined, req: number): void;
4946
export declare class C {
5047
ctorField: {
5148
name: string;
@@ -64,7 +61,7 @@ export declare class C {
6461
}): void;
6562
methodWithRequiredDefault(p: {
6663
name: string;
67-
}, req: number): void;
64+
} | undefined, req: number): void;
6865
constructor(ctorField?: {
6966
name: string;
7067
});
@@ -80,4 +77,6 @@ declare const _default: {
8077
};
8178
export default _default;
8279
// allows `undefined` on the input side, thanks to the initializer
83-
export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
80+
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
81+
name: string;
82+
} | undefined, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode1(strictnullchecks=true).js.diff

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
--- old.declarationEmitCastReusesTypeNode1(strictnullchecks=true).js
22
+++ new.declarationEmitCastReusesTypeNode1(strictnullchecks=true).js
3-
@@= skipped -33, +33 lines =@@
4-
type P = {} & {
5-
name: string;
6-
};
3+
@@= skipped -30, +30 lines =@@
4+
5+
6+
//// [declarationEmitCastReusesTypeNode1.d.ts]
7+
-type P = {} & {
8+
- name: string;
9+
-};
710
-export declare let vLet: P;
811
-export declare const vConst: P;
912
-export declare function fn(p?: P): void;
@@ -19,7 +22,7 @@
1922
+}): void;
2023
+export declare function fnWithRequiredDefaultParam(p: {
2124
+ name: string;
22-
+}, req: number): void;
25+
+} | undefined, req: number): void;
2326
export declare class C {
2427
- ctorField: P;
2528
- field: P;
@@ -47,7 +50,7 @@
4750
+ }): void;
4851
+ methodWithRequiredDefault(p: {
4952
+ name: string;
50-
+ }, req: number): void;
53+
+ } | undefined, req: number): void;
5154
+ constructor(ctorField?: {
5255
+ name: string;
5356
+ });
@@ -65,4 +68,6 @@
6568
export default _default;
6669
-export declare function fnWithPartialAnnotationOnDefaultparam(x: P | undefined, b: number): void;
6770
+// allows `undefined` on the input side, thanks to the initializer
68-
+export declare function fnWithPartialAnnotationOnDefaultparam(x: P, b: number): void;
71+
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
72+
+ name: string;
73+
+} | undefined, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode2(strictnullchecks=false).js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ declare const _default: {
7575
};
7676
export default _default;
7777
// allows `undefined` on the input side, thanks to the initializer
78-
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
78+
export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
7979
name: string;
8080
}, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode2(strictnullchecks=false).js.diff

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
name: string;
7676
};
7777
export default _default;
78-
-export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
7978
+// allows `undefined` on the input side, thanks to the initializer
80-
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
79+
export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
8180
name: string;
8281
}, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode2(strictnullchecks=true).js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export declare function fn(p?: {
4040
}): void;
4141
export declare function fnWithRequiredDefaultParam(p: {
4242
name: string;
43-
}, req: number): void;
43+
} | undefined, req: number): void;
4444
export declare class C {
4545
ctorField: {
4646
name: string;
@@ -59,7 +59,7 @@ export declare class C {
5959
}): void;
6060
methodWithRequiredDefault(p: {
6161
name: string;
62-
}, req: number): void;
62+
} | undefined, req: number): void;
6363
constructor(ctorField?: {
6464
name: string;
6565
});
@@ -75,6 +75,6 @@ declare const _default: {
7575
};
7676
export default _default;
7777
// allows `undefined` on the input side, thanks to the initializer
78-
export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
78+
export declare function fnWithPartialAnnotationOnDefaultparam(x: {
7979
name: string;
80-
}, b: number): void;
80+
} | undefined, b: number): void;

testdata/baselines/reference/submodule/compiler/declarationEmitCastReusesTypeNode2(strictnullchecks=true).js.diff

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
+export declare function fnWithRequiredDefaultParam(p: {
2525
name: string;
2626
-}) | undefined, req: number): void;
27-
+}, req: number): void;
27+
+} | undefined, req: number): void;
2828
export declare class C {
2929
- ctorField: {} & {
3030
- name: string;
@@ -59,7 +59,7 @@
5959
name: string;
6060
- }) | undefined, req: number): void;
6161
- constructor(ctorField?: {} & {
62-
+ }, req: number): void;
62+
+ } | undefined, req: number): void;
6363
+ constructor(ctorField?: {
6464
name: string;
6565
});
@@ -79,7 +79,7 @@
7979
export default _default;
8080
-export declare function fnWithPartialAnnotationOnDefaultparam(x: ({} & {
8181
+// allows `undefined` on the input side, thanks to the initializer
82-
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {} & {
82+
+export declare function fnWithPartialAnnotationOnDefaultparam(x: {
8383
name: string;
8484
-}) | undefined, b: number): void;
85-
+}, b: number): void;
85+
+} | undefined, b: number): void;

0 commit comments

Comments
 (0)