mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 22:32:33 -05:00
Don't issue implicit any when obtaining the implied type for a binding pattern (#60083)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
@@ -11633,7 +11633,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);
|
||||
@@ -40523,7 +40523,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);
|
||||
@@ -40537,6 +40537,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) {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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[]
|
||||
> : ^^^^^^^^
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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[]
|
||||
> : ^^^^^^^^
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration9.ts] ////
|
||||
|
||||
=== index.js ===
|
||||
/**
|
||||
* @param {Object} [config]
|
||||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles]
|
||||
*/
|
||||
export function prepareConfig({
|
||||
>prepareConfig : Symbol(prepareConfig, Decl(index.js, 0, 0))
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : Symbol(additionalFiles, Decl(index.js, 2, 3))
|
||||
|
||||
json = []
|
||||
>json : Symbol(json, Decl(index.js, 5, 22))
|
||||
|
||||
} = {}
|
||||
} = {}) {
|
||||
json // string[]
|
||||
>json : Symbol(json, Decl(index.js, 5, 22))
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
>prepareConfigWithoutAnnotation : Symbol(prepareConfigWithoutAnnotation, Decl(index.js, 10, 1))
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : Symbol(additionalFiles)
|
||||
|
||||
json = []
|
||||
>json : Symbol(json, Decl(index.js, 13, 22))
|
||||
|
||||
} = {}
|
||||
} = {}) {
|
||||
json
|
||||
>json : Symbol(json, Decl(index.js, 13, 22))
|
||||
}
|
||||
|
||||
/** @type {(param: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void} */
|
||||
export const prepareConfigWithContextualSignature = ({
|
||||
>prepareConfigWithContextualSignature : Symbol(prepareConfigWithContextualSignature, Decl(index.js, 23, 12))
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : Symbol(additionalFiles, Decl(index.js, 20, 20))
|
||||
|
||||
json = []
|
||||
>json : Symbol(json, Decl(index.js, 24, 22))
|
||||
|
||||
} = {}
|
||||
} = {})=> {
|
||||
json // string[]
|
||||
>json : Symbol(json, Decl(index.js, 24, 22))
|
||||
}
|
||||
|
||||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
/**
|
||||
* @param {{ a?: { json?: string[] }}} [config]
|
||||
*/
|
||||
function f1({ a: { json = [] } = {} } = {}) { return json }
|
||||
>f1 : Symbol(f1, Decl(index.js, 29, 1))
|
||||
>a : Symbol(a, Decl(index.js, 34, 12))
|
||||
>json : Symbol(json, Decl(index.js, 36, 18))
|
||||
>json : Symbol(json, Decl(index.js, 36, 18))
|
||||
|
||||
/**
|
||||
* @param {[[string[]?]?]} [x]
|
||||
*/
|
||||
function f2([[json = []] = []] = []) { return json }
|
||||
>f2 : Symbol(f2, Decl(index.js, 36, 59))
|
||||
>json : Symbol(json, Decl(index.js, 41, 14))
|
||||
>json : Symbol(json, Decl(index.js, 41, 14))
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration9.ts] ////
|
||||
|
||||
=== index.js ===
|
||||
/**
|
||||
* @param {Object} [config]
|
||||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles]
|
||||
*/
|
||||
export function prepareConfig({
|
||||
>prepareConfig : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;}) => void
|
||||
> : ^ ^^^ ^^^ ^ ^^^^^^^^^
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : any
|
||||
> : ^^^
|
||||
|
||||
json = []
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
>[] : undefined[]
|
||||
> : ^^^^^^^^^^^
|
||||
|
||||
} = {}
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
} = {}) {
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
json // string[]
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
>prepareConfigWithoutAnnotation : ({ additionalFiles: { json } }?: { additionalFiles?: { json?: any[]; }; }) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : any
|
||||
> : ^^^
|
||||
|
||||
json = []
|
||||
>json : any[]
|
||||
> : ^^^^^
|
||||
>[] : undefined[]
|
||||
> : ^^^^^^^^^^^
|
||||
|
||||
} = {}
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
} = {}) {
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
json
|
||||
>json : any[]
|
||||
> : ^^^^^
|
||||
}
|
||||
|
||||
/** @type {(param: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void} */
|
||||
export const prepareConfigWithContextualSignature = ({
|
||||
>prepareConfigWithContextualSignature : (param: { 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[]
|
||||
> : ^^^^^^^^
|
||||
}
|
||||
|
||||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
/**
|
||||
* @param {{ a?: { json?: string[] }}} [config]
|
||||
*/
|
||||
function f1({ a: { json = [] } = {} } = {}) { return json }
|
||||
>f1 : ({ a: { json } }?: { a?: { json?: string[]; }; }) => string[]
|
||||
> : ^ ^^^ ^^^^^^^^^^^^^
|
||||
>a : any
|
||||
> : ^^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
>[] : undefined[]
|
||||
> : ^^^^^^^^^^^
|
||||
>{} : {}
|
||||
> : ^^
|
||||
>{} : {}
|
||||
> : ^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
|
||||
/**
|
||||
* @param {[[string[]?]?]} [x]
|
||||
*/
|
||||
function f2([[json = []] = []] = []) { return json }
|
||||
>f2 : ([[json]]?: [[string[]?]?]) => string[]
|
||||
> : ^ ^^^ ^^^^^^^^^^^^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
>[] : undefined[]
|
||||
> : ^^^^^^^^^^^
|
||||
>[] : []
|
||||
> : ^^
|
||||
>[] : []
|
||||
> : ^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
index.js(15,9): error TS7031: Binding element 'json' implicitly has an 'any[]' type.
|
||||
|
||||
|
||||
==== index.js (1 errors) ====
|
||||
/**
|
||||
* @param {Object} [config]
|
||||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles]
|
||||
*/
|
||||
export function prepareConfig({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {}) {
|
||||
json // string[]
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
~~~~
|
||||
!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type.
|
||||
} = {}
|
||||
} = {}) {
|
||||
json
|
||||
}
|
||||
|
||||
/** @type {(param: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void} */
|
||||
export const prepareConfigWithContextualSignature = ({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {})=> {
|
||||
json // string[]
|
||||
}
|
||||
|
||||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
/**
|
||||
* @param {{ a?: { json?: string[] }}} [config]
|
||||
*/
|
||||
function f1({ a: { json = [] } = {} } = {}) { return json }
|
||||
|
||||
/**
|
||||
* @param {[[string[]?]?]} [x]
|
||||
*/
|
||||
function f2([[json = []] = []] = []) { return json }
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration9.ts] ////
|
||||
|
||||
=== index.js ===
|
||||
/**
|
||||
* @param {Object} [config]
|
||||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles]
|
||||
*/
|
||||
export function prepareConfig({
|
||||
>prepareConfig : Symbol(prepareConfig, Decl(index.js, 0, 0))
|
||||
|
||||
additionalFiles: {
|
||||
json = []
|
||||
>json : Symbol(json, Decl(index.js, 5, 22))
|
||||
|
||||
} = {}
|
||||
} = {}) {
|
||||
json // string[]
|
||||
>json : Symbol(json, Decl(index.js, 5, 22))
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
>prepareConfigWithoutAnnotation : Symbol(prepareConfigWithoutAnnotation, Decl(index.js, 10, 1))
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : Symbol(additionalFiles)
|
||||
|
||||
json = []
|
||||
>json : Symbol(json, Decl(index.js, 13, 22))
|
||||
|
||||
} = {}
|
||||
} = {}) {
|
||||
json
|
||||
>json : Symbol(json, Decl(index.js, 13, 22))
|
||||
}
|
||||
|
||||
/** @type {(param: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void} */
|
||||
export const prepareConfigWithContextualSignature = ({
|
||||
>prepareConfigWithContextualSignature : Symbol(prepareConfigWithContextualSignature, Decl(index.js, 23, 12))
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : Symbol(additionalFiles, Decl(index.js, 20, 20))
|
||||
|
||||
json = []
|
||||
>json : Symbol(json, Decl(index.js, 24, 22))
|
||||
|
||||
} = {}
|
||||
} = {})=> {
|
||||
json // string[]
|
||||
>json : Symbol(json, Decl(index.js, 24, 22))
|
||||
}
|
||||
|
||||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
/**
|
||||
* @param {{ a?: { json?: string[] }}} [config]
|
||||
*/
|
||||
function f1({ a: { json = [] } = {} } = {}) { return json }
|
||||
>f1 : Symbol(f1, Decl(index.js, 29, 1))
|
||||
>json : Symbol(json, Decl(index.js, 36, 18))
|
||||
>json : Symbol(json, Decl(index.js, 36, 18))
|
||||
|
||||
/**
|
||||
* @param {[[string[]?]?]} [x]
|
||||
*/
|
||||
function f2([[json = []] = []] = []) { return json }
|
||||
>f2 : Symbol(f2, Decl(index.js, 36, 59))
|
||||
>json : Symbol(json, Decl(index.js, 41, 14))
|
||||
>json : Symbol(json, Decl(index.js, 41, 14))
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
//// [tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration9.ts] ////
|
||||
|
||||
=== index.js ===
|
||||
/**
|
||||
* @param {Object} [config]
|
||||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles]
|
||||
*/
|
||||
export function prepareConfig({
|
||||
>prepareConfig : ({ additionalFiles: { json } }?: { additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>> | undefined;}) => void
|
||||
> : ^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : any
|
||||
> : ^^^
|
||||
|
||||
json = []
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
>[] : never[]
|
||||
> : ^^^^^^^
|
||||
|
||||
} = {}
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
} = {}) {
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
json // string[]
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
>prepareConfigWithoutAnnotation : ({ additionalFiles: { json } }?: { additionalFiles?: { json?: never[] | undefined; } | undefined; }) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
additionalFiles: {
|
||||
>additionalFiles : any
|
||||
> : ^^^
|
||||
|
||||
json = []
|
||||
>json : any[]
|
||||
> : ^^^^^
|
||||
>[] : never[]
|
||||
> : ^^^^^^^
|
||||
|
||||
} = {}
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
} = {}) {
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
json
|
||||
>json : any[]
|
||||
> : ^^^^^
|
||||
}
|
||||
|
||||
/** @type {(param: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void} */
|
||||
export const prepareConfigWithContextualSignature = ({
|
||||
>prepareConfigWithContextualSignature : (param: { 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[]
|
||||
> : ^^^^^^^^
|
||||
>[] : never[]
|
||||
> : ^^^^^^^
|
||||
|
||||
} = {}
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
} = {})=> {
|
||||
>{} : {}
|
||||
> : ^^
|
||||
|
||||
json // string[]
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
}
|
||||
|
||||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
/**
|
||||
* @param {{ a?: { json?: string[] }}} [config]
|
||||
*/
|
||||
function f1({ a: { json = [] } = {} } = {}) { return json }
|
||||
>f1 : ({ a: { json } }?: { a?: { json?: string[]; }; }) => string[]
|
||||
> : ^ ^^^ ^^^^^^^^^^^^^
|
||||
>a : any
|
||||
> : ^^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
>[] : never[]
|
||||
> : ^^^^^^^
|
||||
>{} : {}
|
||||
> : ^^
|
||||
>{} : {}
|
||||
> : ^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
|
||||
/**
|
||||
* @param {[[string[]?]?]} [x]
|
||||
*/
|
||||
function f2([[json = []] = []] = []) { return json }
|
||||
>f2 : ([[json]]?: [[string[]?]?]) => string[]
|
||||
> : ^ ^^^ ^^^^^^^^^^^^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
>[] : never[]
|
||||
> : ^^^^^^^
|
||||
>[] : []
|
||||
> : ^^
|
||||
>[] : []
|
||||
> : ^^
|
||||
>json : string[]
|
||||
> : ^^^^^^^^
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// @strict: true, false
|
||||
// @noEmit: true
|
||||
|
||||
export function prepareConfig({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
}: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
} = {}) {
|
||||
json // string[]
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {}) {
|
||||
json
|
||||
}
|
||||
|
||||
export const prepareConfigWithContextualSignature: (param:{
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void = ({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {}) => {
|
||||
json // string[]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// @strict: true, false
|
||||
// @noEmit: true
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
// @filename: index.js
|
||||
|
||||
/**
|
||||
* @param {Object} [config]
|
||||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles]
|
||||
*/
|
||||
export function prepareConfig({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {}) {
|
||||
json // string[]
|
||||
}
|
||||
|
||||
export function prepareConfigWithoutAnnotation({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {}) {
|
||||
json
|
||||
}
|
||||
|
||||
/** @type {(param: {
|
||||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>;
|
||||
}) => void} */
|
||||
export const prepareConfigWithContextualSignature = ({
|
||||
additionalFiles: {
|
||||
json = []
|
||||
} = {}
|
||||
} = {})=> {
|
||||
json // string[]
|
||||
}
|
||||
|
||||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936
|
||||
|
||||
/**
|
||||
* @param {{ a?: { json?: string[] }}} [config]
|
||||
*/
|
||||
function f1({ a: { json = [] } = {} } = {}) { return json }
|
||||
|
||||
/**
|
||||
* @param {[[string[]?]?]} [x]
|
||||
*/
|
||||
function f2([[json = []] = []] = []) { return json }
|
||||
Reference in New Issue
Block a user