Skip to content

Commit

Permalink
🤖 Pick PR #60083 (Don't issue implicit any when obtai...) into releas…
Browse files Browse the repository at this point in the history
…e-5.6 (#60086)

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
  • Loading branch information
typescript-bot and ahejlsberg authored Oct 8, 2024
1 parent ff71692 commit fefa70a
Show file tree
Hide file tree
Showing 12 changed files with 863 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11906,7 +11906,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
// pattern.
const contextualType = isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
return addOptionality(getWidenedLiteralTypeForInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
}
if (isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
Expand Down Expand Up @@ -40500,7 +40500,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

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

function getWidenedLiteralTypeForInitializer(declaration: HasExpressionInitializer, type: Type) {
return getCombinedNodeFlagsCached(declaration) & NodeFlags.Constant || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
}

function isLiteralOfContextualType(candidateType: Type, contextualType: Type | undefined): boolean {
if (contextualType) {
if (contextualType.flags & TypeFlags.UnionOrIntersection) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////

=== destructuringParameterDeclaration10.ts ===
export function prepareConfig({
>prepareConfig : Symbol(prepareConfig, Decl(destructuringParameterDeclaration10.ts, 0, 0))

additionalFiles: {
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))

json = []
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))

} = {}
}: {
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))

} = {}) {
json // string[]
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))
}

export function prepareConfigWithoutAnnotation({
>prepareConfigWithoutAnnotation : Symbol(prepareConfigWithoutAnnotation, Decl(destructuringParameterDeclaration10.ts, 8, 1))

additionalFiles: {
>additionalFiles : Symbol(additionalFiles)

json = []
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))

} = {}
} = {}) {
json
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))
}

export const prepareConfigWithContextualSignature: (param:{
>prepareConfigWithContextualSignature : Symbol(prepareConfigWithContextualSignature, Decl(destructuringParameterDeclaration10.ts, 18, 12))
>param : Symbol(param, Decl(destructuringParameterDeclaration10.ts, 18, 52))

additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))

}) => void = ({
additionalFiles: {
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))

json = []
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))

} = {}
} = {}) => {
json // string[]
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////

=== destructuringParameterDeclaration10.ts ===
export function prepareConfig({
>prepareConfig : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
> : ^ ^^^ ^^^^^^^^^

additionalFiles: {
>additionalFiles : any
> : ^^^

json = []
>json : string[]
> : ^^^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^

} = {}
>{} : {}
> : ^^

}: {
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

} = {}) {
>{} : {}
> : ^^

json // string[]
>json : string[]
> : ^^^^^^^^
}

export function prepareConfigWithoutAnnotation({
>prepareConfigWithoutAnnotation : ({ additionalFiles: { json } }?: { additionalFiles?: { json?: any[]; }; }) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

additionalFiles: {
>additionalFiles : any
> : ^^^

json = []
>json : any[]
> : ^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^

} = {}
>{} : {}
> : ^^

} = {}) {
>{} : {}
> : ^^

json
>json : any[]
> : ^^^^^
}

export const prepareConfigWithContextualSignature: (param:{
>prepareConfigWithContextualSignature : (param: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
> : ^ ^^ ^^^^^
>param : { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }
> : ^^^^^^^^^^^^^^^^^^^^ ^^^

additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

}) => void = ({
>({ additionalFiles: { json = [] } = {}} = {}) => { json // string[]} : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^

additionalFiles: {
>additionalFiles : any
> : ^^^

json = []
>json : string[]
> : ^^^^^^^^
>[] : undefined[]
> : ^^^^^^^^^^^

} = {}
>{} : {}
> : ^^

} = {}) => {
>{} : {}
> : ^^

json // string[]
>json : string[]
> : ^^^^^^^^
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////

=== destructuringParameterDeclaration10.ts ===
export function prepareConfig({
>prepareConfig : Symbol(prepareConfig, Decl(destructuringParameterDeclaration10.ts, 0, 0))

additionalFiles: {
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))

json = []
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))

} = {}
}: {
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 4, 4))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))

} = {}) {
json // string[]
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 1, 22))
}

export function prepareConfigWithoutAnnotation({
>prepareConfigWithoutAnnotation : Symbol(prepareConfigWithoutAnnotation, Decl(destructuringParameterDeclaration10.ts, 8, 1))

additionalFiles: {
>additionalFiles : Symbol(additionalFiles)

json = []
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))

} = {}
} = {}) {
json
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 11, 22))
}

export const prepareConfigWithContextualSignature: (param:{
>prepareConfigWithContextualSignature : Symbol(prepareConfigWithContextualSignature, Decl(destructuringParameterDeclaration10.ts, 18, 12))
>param : Symbol(param, Decl(destructuringParameterDeclaration10.ts, 18, 52))

additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))

}) => void = ({
additionalFiles: {
>additionalFiles : Symbol(additionalFiles, Decl(destructuringParameterDeclaration10.ts, 18, 59))

json = []
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))

} = {}
} = {}) => {
json // string[]
>json : Symbol(json, Decl(destructuringParameterDeclaration10.ts, 21, 22))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration10.ts] ////

=== destructuringParameterDeclaration10.ts ===
export function prepareConfig({
>prepareConfig : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
> : ^ ^^^ ^^^^^^^^^

additionalFiles: {
>additionalFiles : any
> : ^^^

json = []
>json : string[]
> : ^^^^^^^^
>[] : never[]
> : ^^^^^^^

} = {}
>{} : {}
> : ^^

}: {
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>> | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

} = {}) {
>{} : {}
> : ^^

json // string[]
>json : string[]
> : ^^^^^^^^
}

export function prepareConfigWithoutAnnotation({
>prepareConfigWithoutAnnotation : ({ additionalFiles: { json } }?: { additionalFiles?: { json?: never[] | undefined; } | undefined; }) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

additionalFiles: {
>additionalFiles : any
> : ^^^

json = []
>json : never[]
> : ^^^^^^^
>[] : never[]
> : ^^^^^^^

} = {}
>{} : {}
> : ^^

} = {}) {
>{} : {}
> : ^^

json
>json : never[]
> : ^^^^^^^
}

export const prepareConfigWithContextualSignature: (param:{
>prepareConfigWithContextualSignature : (param: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
> : ^ ^^ ^^^^^
>param : { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }
> : ^^^^^^^^^^^^^^^^^^^^ ^^^

additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
>additionalFiles : Partial<Record<"json" | "jsonc" | "json5", string[]>> | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

}) => void = ({
>({ additionalFiles: { json = [] } = {}} = {}) => { json // string[]} : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; }) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^

additionalFiles: {
>additionalFiles : any
> : ^^^

json = []
>json : string[]
> : ^^^^^^^^
>[] : never[]
> : ^^^^^^^

} = {}
>{} : {}
> : ^^

} = {}) => {
>{} : {}
> : ^^

json // string[]
>json : string[]
> : ^^^^^^^^
}

Loading

0 comments on commit fefa70a

Please sign in to comment.