Skip to content

Commit fefa70a

Browse files
🤖 Pick PR #60083 (Don't issue implicit any when obtai...) into release-5.6 (#60086)
Co-authored-by: Anders Hejlsberg <[email protected]>
1 parent ff71692 commit fefa70a

12 files changed

+863
-2
lines changed

‎src/compiler/checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11906,7 +11906,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1190611906
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
1190711907
// pattern.
1190811908
const contextualType = isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
11909-
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
11909+
return addOptionality(getWidenedLiteralTypeForInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
1191011910
}
1191111911
if (isBindingPattern(element.name)) {
1191211912
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -40500,7 +40500,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4050040500
}
4050140501

4050240502
function widenTypeInferredFromInitializer(declaration: HasExpressionInitializer, type: Type) {
40503-
const widened = getCombinedNodeFlagsCached(declaration) & NodeFlags.Constant || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
40503+
const widened = getWidenedLiteralTypeForInitializer(declaration, type);
4050440504
if (isInJSFile(declaration)) {
4050540505
if (isEmptyLiteralType(widened)) {
4050640506
reportImplicitAny(declaration, anyType);
@@ -40514,6 +40514,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4051440514
return widened;
4051540515
}
4051640516

40517+
function getWidenedLiteralTypeForInitializer(declaration: HasExpressionInitializer, type: Type) {
40518+
return getCombinedNodeFlagsCached(declaration) & NodeFlags.Constant || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
40519+
}
40520+
4051740521
function isLiteralOfContextualType(candidateType: Type, contextualType: Type | undefined): boolean {
4051840522
if (contextualType) {
4051940523
if (contextualType.flags & TypeFlags.UnionOrIntersection) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////
2+
3+
=== destructuringParameterDeclaration10.ts ===
4+
export function prepareConfig({
5+
>prepareConfig : Symbol(prepareConfig, Decl(destructuringParameterDeclaration10.ts, 0, 0))
6+
7+
additionalFiles: {
8+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))
9+
10+
json = []
11+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))
12+
13+
} = {}
14+
}: {
15+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
16+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))
17+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
18+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
19+
20+
} = {}) {
21+
json // string[]
22+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))
23+
}
24+
25+
export function prepareConfigWithoutAnnotation({
26+
>prepareConfigWithoutAnnotation : Symbol(prepareConfigWithoutAnnotation, Decl(destructuringParameterDeclaration10.ts, 8, 1))
27+
28+
additionalFiles: {
29+
>additionalFiles : Symbol(additionalFiles)
30+
31+
json = []
32+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))
33+
34+
} = {}
35+
} = {}) {
36+
json
37+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))
38+
}
39+
40+
export const prepareConfigWithContextualSignature: (param:{
41+
>prepareConfigWithContextualSignature : Symbol(prepareConfigWithContextualSignature, Decl(destructuringParameterDeclaration10.ts, 18, 12))
42+
>param : Symbol(param, Decl(destructuringParameterDeclaration10.ts, 18, 52))
43+
44+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
45+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))
46+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
47+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
48+
49+
}) => void = ({
50+
additionalFiles: {
51+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))
52+
53+
json = []
54+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))
55+
56+
} = {}
57+
} = {}) => {
58+
json // string[]
59+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))
60+
}
61+
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////
2+
3+
=== destructuringParameterDeclaration10.ts ===
4+
export function prepareConfig({
5+
>prepareConfig : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
6+
> : ^ ^^^ ^^^^^^^^^
7+
8+
additionalFiles: {
9+
>additionalFiles : any
10+
> : ^^^
11+
12+
json = []
13+
>json : string[]
14+
> : ^^^^^^^^
15+
>[] : undefined[]
16+
> : ^^^^^^^^^^^
17+
18+
} = {}
19+
>{} : {}
20+
> : ^^
21+
22+
}: {
23+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
24+
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>>
25+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
} = {}) {
28+
>{} : {}
29+
> : ^^
30+
31+
json // string[]
32+
>json : string[]
33+
> : ^^^^^^^^
34+
}
35+
36+
export function prepareConfigWithoutAnnotation({
37+
>prepareConfigWithoutAnnotation : ({ additionalFiles: { json } }?: { additionalFiles?: { json?: any[]; }; }) => void
38+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
40+
additionalFiles: {
41+
>additionalFiles : any
42+
> : ^^^
43+
44+
json = []
45+
>json : any[]
46+
> : ^^^^^
47+
>[] : undefined[]
48+
> : ^^^^^^^^^^^
49+
50+
} = {}
51+
>{} : {}
52+
> : ^^
53+
54+
} = {}) {
55+
>{} : {}
56+
> : ^^
57+
58+
json
59+
>json : any[]
60+
> : ^^^^^
61+
}
62+
63+
export const prepareConfigWithContextualSignature: (param:{
64+
>prepareConfigWithContextualSignature : (param: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
65+
> : ^ ^^ ^^^^^
66+
>param : { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }
67+
> : ^^^^^^^^^^^^^^^^^^^^ ^^^
68+
69+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
70+
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>>
71+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
73+
}) => void = ({
74+
>({ additionalFiles: { json = [] } = {}} = {}) => { json // string[]} : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
75+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
76+
77+
additionalFiles: {
78+
>additionalFiles : any
79+
> : ^^^
80+
81+
json = []
82+
>json : string[]
83+
> : ^^^^^^^^
84+
>[] : undefined[]
85+
> : ^^^^^^^^^^^
86+
87+
} = {}
88+
>{} : {}
89+
> : ^^
90+
91+
} = {}) => {
92+
>{} : {}
93+
> : ^^
94+
95+
json // string[]
96+
>json : string[]
97+
> : ^^^^^^^^
98+
}
99+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////
2+
3+
=== destructuringParameterDeclaration10.ts ===
4+
export function prepareConfig({
5+
>prepareConfig : Symbol(prepareConfig, Decl(destructuringParameterDeclaration10.ts, 0, 0))
6+
7+
additionalFiles: {
8+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))
9+
10+
json = []
11+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))
12+
13+
} = {}
14+
}: {
15+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
16+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))
17+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
18+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
19+
20+
} = {}) {
21+
json // string[]
22+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))
23+
}
24+
25+
export function prepareConfigWithoutAnnotation({
26+
>prepareConfigWithoutAnnotation : Symbol(prepareConfigWithoutAnnotation, Decl(destructuringParameterDeclaration10.ts, 8, 1))
27+
28+
additionalFiles: {
29+
>additionalFiles : Symbol(additionalFiles)
30+
31+
json = []
32+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))
33+
34+
} = {}
35+
} = {}) {
36+
json
37+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))
38+
}
39+
40+
export const prepareConfigWithContextualSignature: (param:{
41+
>prepareConfigWithContextualSignature : Symbol(prepareConfigWithContextualSignature, Decl(destructuringParameterDeclaration10.ts, 18, 12))
42+
>param : Symbol(param, Decl(destructuringParameterDeclaration10.ts, 18, 52))
43+
44+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
45+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))
46+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
47+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
48+
49+
}) => void = ({
50+
additionalFiles: {
51+
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))
52+
53+
json = []
54+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))
55+
56+
} = {}
57+
} = {}) => {
58+
json // string[]
59+
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))
60+
}
61+
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////
2+
3+
=== destructuringParameterDeclaration10.ts ===
4+
export function prepareConfig({
5+
>prepareConfig : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
6+
> : ^ ^^^ ^^^^^^^^^
7+
8+
additionalFiles: {
9+
>additionalFiles : any
10+
> : ^^^
11+
12+
json = []
13+
>json : string[]
14+
> : ^^^^^^^^
15+
>[] : never[]
16+
> : ^^^^^^^
17+
18+
} = {}
19+
>{} : {}
20+
> : ^^
21+
22+
}: {
23+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
24+
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>> | undefined
25+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
} = {}) {
28+
>{} : {}
29+
> : ^^
30+
31+
json // string[]
32+
>json : string[]
33+
> : ^^^^^^^^
34+
}
35+
36+
export function prepareConfigWithoutAnnotation({
37+
>prepareConfigWithoutAnnotation : ({ additionalFiles: { json } }?: { additionalFiles?: { json?: never[] | undefined; } | undefined; }) => void
38+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
40+
additionalFiles: {
41+
>additionalFiles : any
42+
> : ^^^
43+
44+
json = []
45+
>json : never[]
46+
> : ^^^^^^^
47+
>[] : never[]
48+
> : ^^^^^^^
49+
50+
} = {}
51+
>{} : {}
52+
> : ^^
53+
54+
} = {}) {
55+
>{} : {}
56+
> : ^^
57+
58+
json
59+
>json : never[]
60+
> : ^^^^^^^
61+
}
62+
63+
export const prepareConfigWithContextualSignature: (param:{
64+
>prepareConfigWithContextualSignature : (param: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
65+
> : ^ ^^ ^^^^^
66+
>param : { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }
67+
> : ^^^^^^^^^^^^^^^^^^^^ ^^^
68+
69+
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
70+
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>> | undefined
71+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
73+
}) => void = ({
74+
>({ additionalFiles: { json = [] } = {}} = {}) => { json // string[]} : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
75+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
76+
77+
additionalFiles: {
78+
>additionalFiles : any
79+
> : ^^^
80+
81+
json = []
82+
>json : string[]
83+
> : ^^^^^^^^
84+
>[] : never[]
85+
> : ^^^^^^^
86+
87+
} = {}
88+
>{} : {}
89+
> : ^^
90+
91+
} = {}) => {
92+
>{} : {}
93+
> : ^^
94+
95+
json // string[]
96+
>json : string[]
97+
> : ^^^^^^^^
98+
}
99+

0 commit comments

Comments
 (0)