You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
7.1: array-destructured parameter with a = [] default loses its contextual type (TS7031) #65069
The object form from #64974 fails the same way; this report is specifically the array form:
typeG=(input?: {a?: string;b?: number})=>number;exportconstg: G=({ a, b }={})=>(a ? 1 : 0)+(b??0);// also TS7031; tracked in #64974
Without the = [] initializer, the array pattern still checks cleanly on 7.1:
typeF2=(input: [string?,number?])=>number;exportconstf2: F2=([a,b])=>(a ? 1 : 0)+(b??0);// OK
🙁 Actual behavior
repro.ts(2,23): error TS7031: Binding element 'a' implicitly has an 'any' type.
repro.ts(2,26): error TS7031: Binding element 'b' implicitly has an 'any' type.
🙂 Expected behavior
No errors: a and b take string | undefined and number | undefined from the contextual parameter type, as on 7.0.2.
Additional information about the issue
In checkDeclarationInitializer, parameter array binding patterns always call padTupleType when the initializer type is a tuple. Padding invents any-typed missing elements and overrides the contextual parameter type:
case ast.KindArrayBindingPattern:
ifisTupleType(t) {
returnc.padTupleType(t, name)
}
#64978 adds a contextual-type guard only for KindObjectBindingPattern / padObjectLiteralType. After that lands, this array case will still fail unless padTupleType gets the same getContextualTypeForVariableLikeDeclaration(root, ContextFlagsNone) == nil guard.
Activity