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
Contextual typing of destructuring parameters seems to be an obvious idea, but I could not find any mention of this in 1.5 spec draft in master branch. Just wanted to know if you have plans to do it or not, so we could support it in our external tool.
interface A { field1: number; field2: number }
function f(p: (p1: A) => number) {}
f(({field1, field2}) => {})
The text was updated successfully, but these errors were encountered:
In a variable, parameter, binding property, binding element, or member declaration, an initializer expression is contextually typed by
the type given in the declaration's type annotation, if any, or otherwise
for a parameter, the contextual type for the declaration (section 4.9.3), if any, or otherwise
the type implied by the binding pattern in the declaration (section 5.1.3), if any.
I think what you're looking for is information on binding patterns and implied types.
The view of things for our compiler is that destructuring is the name of a concept that encompasses the use of binding patterns to extract information from an object in a convenient way.
Sorry, I'm not really talking about contextually typing "initializer expression", see my code sample. I'm talking about type associated with a parameter, see section 6.4:
The type of local introduced in a destructuring parameter declaration is determined in the same manner
as a local introduced by a destructuring variable declaration, except the type T associated with a
destructuring parameter declaration is determined as follows:
If the declaration includes a type annotation, T is that type.
Otherwise, if the declaration includes an initializer expression, T is the widened form (section 3.11)
of the type of the initializer expression.
Otherwise, if the declaration specifies a binding pattern, T is the implied type of that binding
pattern (section 5.1.3).
Otherwise, if the parameter is a rest parameter, T is any[].
Otherwise, T is any.
Not a word about contextual typing here, but section 4.9.3 says:
When a function expression with no type parameters and no parameter type annotations is contextually
typed (section 4.19) by a type T and a contextual signature S can be extracted from T, the function
expression is processed as if it had explicitly specified parameter type annotations as they exist in S.
Does that mean that contextual types affect type associated with a parameter, or not? I suggest explicitly mentioning this in the spec or (better) providing an example.
Contextual typing of destructuring parameters seems to be an obvious idea, but I could not find any mention of this in 1.5 spec draft in master branch. Just wanted to know if you have plans to do it or not, so we could support it in our external tool.
The text was updated successfully, but these errors were encountered: