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
[Spec] contextual typing of return expression values #72
interfaceIBookStyle{initialLeftPageTransforms?: (width: number)=>NamedTransform[];}interfaceNamedTransform{[name: string]: Transform3D;}interfaceTransform3D{cachedCss: string;}varstyle: IBookStyle={initialLeftPageTransforms: (width: number)=>{return[{'ry': null}];}}//!!!Type '{ initialLeftPageTransforms: (width: number) => { 'ry': any; }[]; }' is not assignable to type 'IBookStyle'://!!!Types of property 'initialLeftPageTransforms' of types '{ initialLeftPageTransforms: (width: number) => { 'ry': any; }[]; }' and 'IBookStyle' are incompatible://!!!Call signatures of types '(width: number) => { 'ry': any; }[]' and '(width: number) => NamedTransform[]' are incompatible://!!!Types of property 'pop' of types '{ 'ry': any; }[]' and 'NamedTransform[]' are incompatible://!!!Call signatures of types '() => { 'ry': any; }' and '() => NamedTransform' are incompatible://!!!Index signatures of types '{ 'ry': any; }' and 'NamedTransform' are incompatible.
This is because of the type annotation on width, causing the return expression to not be contextually typed. It might make sense for the return expression to be contextually typed, even in the presence of parameter annotations.
Changing to spec issue. In the old compiler we would contextually type the return value of a function expression only if the function expression had no parameter or return type annotations. The new compiler contextually types the return value when the function expression has no return type annotation, regardless of whether there are parameter type annotations. We previously discussed this and agreed we want the new behavior. Spec sections affected are 4.9.3 and 4.19.
changed the title [-][Spec] contextually typed return types of array types[/-][+][Spec] contextually typed return types of function expression types[/+]on Jul 18, 2014
changed the title [-][Spec] contextually typed return types of function expression types[/-][+][Spec] contextual typing of return expression values[/+]on Jul 18, 2014
Activity
JsonFreeman commentedon Jul 17, 2014
This is because of the type annotation on width, causing the return expression to not be contextually typed. It might make sense for the return expression to be contextually typed, even in the presence of parameter annotations.
ahejlsberg commentedon Jul 17, 2014
Changing to spec issue. In the old compiler we would contextually type the return value of a function expression only if the function expression had no parameter or return type annotations. The new compiler contextually types the return value when the function expression has no return type annotation, regardless of whether there are parameter type annotations. We previously discussed this and agreed we want the new behavior. Spec sections affected are 4.9.3 and 4.19.
[-][Errors] contextually typed return types of array types[/-][+][Spec] contextually typed return types of array types[/+][-][Spec] contextually typed return types of array types[/-][+][Spec] contextually typed return types of function expression types[/+][-][Spec] contextually typed return types of function expression types[/-][+][Spec] contextual typing of return expression values[/+]