From fdded507cacfef8b267486576ad5cdaeaa46f85c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 14 Dec 2017 14:27:03 -0800 Subject: [PATCH 1/7] Fix get symbol at location to behave correctly got parameter assignments and jsx attributes --- src/compiler/checker.ts | 51 ++++++++++++------- tests/baselines/reference/ES5For-of31.types | 4 +- .../reference/checkJsxChildrenProperty1.types | 14 ++--- .../checkJsxChildrenProperty13.types | 2 +- .../checkJsxChildrenProperty14.types | 20 ++++---- .../reference/checkJsxChildrenProperty2.types | 30 +++++------ .../reference/checkJsxChildrenProperty5.types | 12 ++--- .../reference/checkJsxChildrenProperty6.types | 16 +++--- .../reference/checkJsxChildrenProperty7.types | 12 ++--- .../reference/checkJsxChildrenProperty8.types | 16 +++--- ...structorWithIncompleteTypeAnnotation.types | 4 +- ...contextualTypeObjectSpreadExpression.types | 2 +- .../contextualTypeShouldBeLiteral.types | 16 +++--- .../contextualTypingOfOptionalMembers.types | 2 +- ...ontextuallyTypedByDiscriminableUnion.types | 2 +- ...TypedStringLiteralsInJsxAttributes01.types | 8 +-- ...TypedStringLiteralsInJsxAttributes02.types | 6 +-- .../destructuredDeclarationEmit.types | 4 +- .../discriminatedUnionErrorMessage.types | 2 +- .../excessPropertyCheckWithUnions.types | 28 +++++----- .../reference/jsxEmitWithAttributes.types | 2 +- .../reference/jsxEsprimaFbTestSuite.types | 24 ++++----- .../jsxFactoryAndReactNamespace.types | 2 +- .../reference/jsxFactoryIdentifier.types | 2 +- ...xFactoryNotIdentifierOrQualifiedName.types | 2 +- ...FactoryNotIdentifierOrQualifiedName2.types | 2 +- .../reference/jsxFactoryQualifiedName.types | 2 +- .../jsxInvalidEsprimaTestSuite.types | 6 +-- .../jsxMultilineAttributeStringValues.types | 4 +- .../jsxMultilineAttributeValuesReact.types | 6 +-- .../reference/jsxParsingError1.types | 2 +- .../reference/jsxPropsAsIdentifierNames.types | 2 +- .../reference/jsxReactTestSuite.types | 26 +++++----- .../reference/keywordInJsxIdentifier.types | 4 +- .../literalIntersectionYieldsLiteral.types | 2 +- tests/baselines/reference/literalTypes2.types | 16 +++--- .../literalTypesAndTypeAssertions.types | 2 +- .../reference/mappedTypeIndexedAccess.types | 4 +- .../nestedTypeVariableInfersLiteral.types | 4 +- .../baselines/reference/objectRestForOf.types | 2 +- .../reference/reactNamespaceJSXEmit.types | 2 +- .../stringLiteralTypesAsTags01.types | 2 +- .../stringLiteralTypesAsTags02.types | 2 +- .../stringLiteralTypesAsTags03.types | 2 +- .../reference/tsxAttributeErrors.types | 8 +-- ...ributeQuickinfoTypesSameAsObjectLiteral.js | 25 +++++++++ ...eQuickinfoTypesSameAsObjectLiteral.symbols | 40 +++++++++++++++ ...uteQuickinfoTypesSameAsObjectLiteral.types | 46 +++++++++++++++++ .../reference/tsxAttributeResolution1.types | 22 ++++---- .../reference/tsxAttributeResolution10.types | 6 +-- .../reference/tsxAttributeResolution11.types | 2 +- .../reference/tsxAttributeResolution14.types | 10 ++-- .../reference/tsxAttributeResolution15.types | 4 +- .../reference/tsxAttributeResolution16.types | 6 +-- .../reference/tsxAttributeResolution3.types | 6 +-- .../reference/tsxAttributeResolution6.types | 4 +- .../reference/tsxAttributeResolution7.types | 8 +-- .../reference/tsxAttributeResolution9.types | 4 +- .../reference/tsxElementResolution.types | 2 +- .../reference/tsxElementResolution10.types | 6 +-- .../reference/tsxElementResolution11.types | 6 +-- .../reference/tsxElementResolution12.types | 10 ++-- .../reference/tsxElementResolution13.types | 2 +- .../reference/tsxElementResolution14.types | 2 +- .../reference/tsxElementResolution15.types | 2 +- .../reference/tsxElementResolution16.types | 2 +- .../reference/tsxElementResolution18.types | 2 +- .../reference/tsxElementResolution3.types | 4 +- .../reference/tsxElementResolution4.types | 6 +-- .../reference/tsxElementResolution5.types | 2 +- .../reference/tsxElementResolution6.types | 2 +- .../reference/tsxElementResolution7.types | 4 +- .../reference/tsxElementResolution9.types | 2 +- .../tsxGenericArrowFunctionParsing.types | 2 +- .../reference/tsxGenericAttributesType1.types | 4 +- .../reference/tsxGenericAttributesType2.types | 2 +- .../reference/tsxGenericAttributesType3.types | 2 +- .../reference/tsxGenericAttributesType4.types | 2 +- .../reference/tsxGenericAttributesType5.types | 2 +- .../reference/tsxGenericAttributesType6.types | 2 +- .../reference/tsxGenericAttributesType7.types | 2 +- .../reference/tsxInArrowFunction.types | 8 +-- ...sxInferenceShouldNotYieldAnyOnUnions.types | 6 +-- ...ctComponentWithDefaultTypeParameter1.types | 4 +- ...ctComponentWithDefaultTypeParameter2.types | 2 +- ...ctComponentWithDefaultTypeParameter3.types | 6 +-- tests/baselines/reference/tsxReactEmit4.types | 2 +- tests/baselines/reference/tsxReactEmit5.types | 4 +- tests/baselines/reference/tsxReactEmit6.types | 4 +- tests/baselines/reference/tsxReactEmit7.types | 18 +++---- .../reference/tsxReactEmitEntities.types | 6 +-- .../reference/tsxReactEmitNesting.types | 30 +++++------ .../tsxSpreadAttributesResolution10.types | 8 +-- .../tsxSpreadAttributesResolution11.types | 24 ++++----- .../tsxSpreadAttributesResolution12.types | 18 +++---- .../tsxSpreadAttributesResolution13.types | 2 +- .../tsxSpreadAttributesResolution15.types | 2 +- .../tsxSpreadAttributesResolution2.types | 6 +-- .../tsxSpreadAttributesResolution3.types | 4 +- .../tsxSpreadAttributesResolution4.types | 2 +- .../tsxSpreadAttributesResolution6.types | 4 +- .../tsxSpreadAttributesResolution7.types | 4 +- .../tsxSpreadAttributesResolution8.types | 2 +- .../tsxSpreadAttributesResolution9.types | 4 +- ...xStatelessFunctionComponentOverload1.types | 38 +++++++------- ...xStatelessFunctionComponentOverload2.types | 6 +-- ...xStatelessFunctionComponentOverload3.types | 16 +++--- ...xStatelessFunctionComponentOverload4.types | 24 ++++----- ...xStatelessFunctionComponentOverload5.types | 6 +-- ...xStatelessFunctionComponentOverload6.types | 14 ++--- ...onComponentWithDefaultTypeParameter1.types | 2 +- ...onComponentWithDefaultTypeParameter2.types | 2 +- .../tsxStatelessFunctionComponents1.types | 16 +++--- .../tsxStatelessFunctionComponents2.types | 6 +-- ...FunctionComponentsWithTypeArguments2.types | 2 +- ...FunctionComponentsWithTypeArguments3.types | 6 +-- ...FunctionComponentsWithTypeArguments5.types | 8 +-- tests/baselines/reference/tsxTypeErrors.types | 8 +-- .../reference/tsxUnionElementType2.types | 2 +- .../reference/tsxUnionElementType3.types | 6 +-- .../reference/tsxUnionElementType4.types | 2 +- .../reference/tsxUnionElementType6.types | 2 +- .../baselines/reference/tsxUnionSpread.types | 4 +- ...ibuteQuickinfoTypesSameAsObjectLiteral.tsx | 19 +++++++ 124 files changed, 570 insertions(+), 427 deletions(-) create mode 100644 tests/baselines/reference/tsxAttributeQuickinfoTypesSameAsObjectLiteral.js create mode 100644 tests/baselines/reference/tsxAttributeQuickinfoTypesSameAsObjectLiteral.symbols create mode 100644 tests/baselines/reference/tsxAttributeQuickinfoTypesSameAsObjectLiteral.types create mode 100644 tests/cases/compiler/tsxAttributeQuickinfoTypesSameAsObjectLiteral.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1b57e5def701..581796e76d2d0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4605,7 +4605,7 @@ namespace ts { // Here, the array literal [1, "one"] is contextually typed by the type [any, string], which is the implied type of the // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string. - function getWidenedTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration, reportErrors?: boolean): Type { + function getWidenedTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement, reportErrors?: boolean): Type { let type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); if (type) { if (reportErrors) { @@ -4613,21 +4613,15 @@ namespace ts { } // always widen a 'unique symbol' type if the type was created for a different declaration. - if (type.flags & TypeFlags.UniqueESSymbol && !declaration.type && type.symbol !== getSymbolOfNode(declaration)) { + if (type.flags & TypeFlags.UniqueESSymbol && (isBindingElement(declaration) || !declaration.type) && type.symbol !== getSymbolOfNode(declaration)) { type = esSymbolType; } - // During a normal type check we'll never get to here with a property assignment (the check of the containing - // object literal uses a different path). We exclude widening only so that language services and type verification - // tools see the actual type. - if (declaration.kind === SyntaxKind.PropertyAssignment) { - return type; - } return getWidenedType(type); } // Rest parameters default to type any[], other parameters default to type any - type = declaration.dotDotDotToken ? anyArrayType : anyType; + type = isParameter(declaration) && declaration.dotDotDotToken ? anyArrayType : anyType; // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors && noImplicitAny) { @@ -4678,8 +4672,21 @@ namespace ts { declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { type = getWidenedTypeFromJSSpecialPropertyDeclarations(symbol); } + else if (isPropertyAssignment(declaration)) { + type = checkPropertyAssignment(declaration); + } + else if (isJsxAttribute(declaration)) { + type = checkJsxAttribute(declaration); + } + else if (isParameter(declaration) + || isPropertyDeclaration(declaration) + || isPropertySignature(declaration) + || isVariableDeclaration(declaration) + || isBindingElement(declaration)) { + type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); + } else { - type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); + Debug.fail("Unhandled declaration kind! " + (ts as any).SyntaxKind[declaration.kind]); } if (!popTypeResolution()) { @@ -14802,6 +14809,12 @@ namespace ts { } } + function checkJsxAttribute(node: JsxAttribute, checkMode?: CheckMode) { + return node.initializer + ? checkExpression(node.initializer, checkMode) + : trueType; // is sugar for + } + /** * Get attributes type of the JSX opening-like element. The result is from resolving "attributes" property of the opening-like element. * @@ -14824,9 +14837,7 @@ namespace ts { for (const attributeDecl of attributes.properties) { const member = attributeDecl.symbol; if (isJsxAttribute(attributeDecl)) { - const exprType = attributeDecl.initializer ? - checkExpression(attributeDecl.initializer, checkMode) : - trueType; // is sugar for + const exprType = checkJsxAttribute(attributeDecl, checkMode); const attributeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.escapedName); attributeSymbol.declarations = member.declarations; @@ -19773,7 +19784,7 @@ namespace ts { } } - function checkPropertyDeclaration(node: PropertyDeclaration) { + function checkPropertyDeclaration(node: PropertyDeclaration | PropertySignature) { // Grammar checking if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarProperty(node)) checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); @@ -21526,9 +21537,11 @@ namespace ts { } // Check variable, parameter, or property declaration - function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { + function checkVariableLikeDeclaration(node: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement) { checkDecorators(node); - checkSourceElement(node.type); + if (!isBindingElement(node)) { + checkSourceElement(node.type); + } // JSDoc `function(string, string): string` syntax results in parameters with no name if (!node.name) { @@ -23693,7 +23706,7 @@ namespace ts { return checkParameter(node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - return checkPropertyDeclaration(node); + return checkPropertyDeclaration(node); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.CallSignature: @@ -26482,7 +26495,7 @@ namespace ts { } } - function checkGrammarProperty(node: PropertyDeclaration) { + function checkGrammarProperty(node: PropertyDeclaration | PropertySignature) { if (isClassLike(node.parent)) { if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type)) { return true; @@ -26509,7 +26522,7 @@ namespace ts { return grammarErrorOnFirstToken(node.initializer, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } - if (node.exclamationToken && (!isClassLike(node.parent) || !node.type || node.initializer || + if (isPropertyDeclaration(node) && node.exclamationToken && (!isClassLike(node.parent) || !node.type || node.initializer || node.flags & NodeFlags.Ambient || hasModifier(node, ModifierFlags.Static | ModifierFlags.Abstract))) { return grammarErrorOnNode(node.exclamationToken, Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context); } diff --git a/tests/baselines/reference/ES5For-of31.types b/tests/baselines/reference/ES5For-of31.types index ee12f3894a8bb..309c8d1cab8c5 100644 --- a/tests/baselines/reference/ES5For-of31.types +++ b/tests/baselines/reference/ES5For-of31.types @@ -5,11 +5,11 @@ var a: string, b: number; for ({ a: b = 1, b: a = ""} of []) { >{ a: b = 1, b: a = ""} : { a?: number; b?: string; } ->a : undefined +>a : number >b = 1 : 1 >b : number >1 : 1 ->b : undefined +>b : string >a = "" : "" >a : string >"" : "" diff --git a/tests/baselines/reference/checkJsxChildrenProperty1.types b/tests/baselines/reference/checkJsxChildrenProperty1.types index 821f95d9ae71b..bf304e3fcd8a0 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty1.types +++ b/tests/baselines/reference/checkJsxChildrenProperty1.types @@ -36,10 +36,10 @@ let k = ; >k : JSX.Element > : JSX.Element >Comp : (p: Prop) => JSX.Element ->a : number +>a : 10 >10 : 10 ->b : string ->children : string +>b : "hi" +>children : "lol" let k1 = >k1 : JSX.Element @@ -47,9 +47,9 @@ let k1 = > hi hi hi! : JSX.Element >Comp : (p: Prop) => JSX.Element ->a : number +>a : 10 >10 : 10 ->b : string +>b : "hi" hi hi hi! ; @@ -61,9 +61,9 @@ let k2 = >
hi hi hi!
: JSX.Element >Comp : (p: Prop) => JSX.Element ->a : number +>a : 10 >10 : 10 ->b : string +>b : "hi"
hi hi hi!
>
hi hi hi!
: JSX.Element diff --git a/tests/baselines/reference/checkJsxChildrenProperty13.types b/tests/baselines/reference/checkJsxChildrenProperty13.types index 10d3876ae6350..5360d78cda4b0 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty13.types +++ b/tests/baselines/reference/checkJsxChildrenProperty13.types @@ -34,7 +34,7 @@ class Button extends React.Component { >this.props : ButtonProp & { children?: React.ReactNode; } >this : this >props : ButtonProp & { children?: React.ReactNode; } ->children : string +>children : "hi"
Hello World
>
Hello World
: JSX.Element diff --git a/tests/baselines/reference/checkJsxChildrenProperty14.types b/tests/baselines/reference/checkJsxChildrenProperty14.types index a0d9797934c9f..2033637751523 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty14.types +++ b/tests/baselines/reference/checkJsxChildrenProperty14.types @@ -65,9 +65,9 @@ let k1 = <>
)} : any >section : any ->class : string +>class : "todoapp"
>

todos <x>

: any >header : any ->class : string +>class : "header"

todos <x>

>

todos <x>

: any @@ -33,10 +33,10 @@ let render = (ctrl, model) => > : any >input : any ->class : string +>class : "new-todo" >autofocus : true ->autocomplete : string ->placeholder : string +>autocomplete : "off" +>placeholder : "What needs to be done?" >value : any >model.newTodo : any >model : any @@ -57,7 +57,7 @@ let render = (ctrl, model) =>
>
    {model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • )}
: any >section : any ->class : string +>class : "main" >style : { display: string; } >{display:(model.todos && model.todos.length) ? "block" : "none"} : { display: string; } >display : string @@ -78,8 +78,8 @@ let render = (ctrl, model) => > : any >input : any ->class : string ->type : string +>class : "toggle-all" +>type : "checkbox" >onChange : any >ctrl.toggleAll.bind(ctrl) : any >ctrl.toggleAll.bind : any @@ -92,7 +92,7 @@ let render = (ctrl, model) =>
: any >section : any ->class : "todoapp" +>class : string
>

todos <x>

: any >header : any ->class : "header" +>class : string

todos <x>

>

todos <x>

: any @@ -33,10 +33,10 @@ let render = (ctrl, model) => > : any >input : any ->class : "new-todo" +>class : string >autofocus : true ->autocomplete : "off" ->placeholder : "What needs to be done?" +>autocomplete : string +>placeholder : string >value : any >model.newTodo : any >model : any @@ -57,7 +57,7 @@ let render = (ctrl, model) =>
>
    {model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • )}
: any >section : any ->class : "main" +>class : string >style : { display: string; } >{display:(model.todos && model.todos.length) ? "block" : "none"} : { display: string; } >display : string @@ -78,8 +78,8 @@ let render = (ctrl, model) => > : any >input : any ->class : "toggle-all" ->type : "checkbox" +>class : string +>type : string >onChange : any >ctrl.toggleAll.bind(ctrl) : any >ctrl.toggleAll.bind : any @@ -92,7 +92,7 @@ let render = (ctrl, model) =>
    >
      {model.filteredTodos.map((todo) =>
    • {(!todo.editable) ? : null }
    • )}
    : any >ul : any ->class : "todo-list" +>class : string {model.filteredTodos.map((todo) => >model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • ) : any @@ -125,7 +125,7 @@ let render = (ctrl, model) =>
    >
    {(!todo.editable) ? : null }
    : any >div : any ->class : "view" +>class : string {(!todo.editable) ? >(!todo.editable) ? : null : any @@ -138,8 +138,8 @@ let render = (ctrl, model) => > : any >input : any ->class : "toggle" ->type : "checkbox" +>class : string +>type : string >input : any : null @@ -163,7 +163,7 @@ let render = (ctrl, model) => > : any >button : any ->class : "destroy" +>class : string >onClick : any >ctrl.removeTodo.bind(ctrl,todo) : any >ctrl.removeTodo.bind : any @@ -178,12 +178,12 @@ let render = (ctrl, model) =>
    >
    : any >div : any ->class : "iconBorder" +>class : string
    >
    : any >div : any ->class : "icon" +>class : string
    >div : any diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution10.types b/tests/baselines/reference/tsxSpreadAttributesResolution10.types index e3a5a4a25067e..09e6188a30a4e 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution10.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution10.types @@ -55,7 +55,7 @@ let y1 = ; > : JSX.Element >Opt : typeof Opt >obj1 : OptionProp ->x : "Hi" +>x : string let y2 = ; >y2 : JSX.Element diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution11.types b/tests/baselines/reference/tsxSpreadAttributesResolution11.types index 9c974edcbb123..aa1fec2a88523 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution11.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution11.types @@ -72,7 +72,7 @@ let x = >OverWriteAttr : typeof OverWriteAttr >obj : {} >y : true ->overwrite : "hi" +>overwrite : string >obj1 : { x: 2; } let x1 = @@ -88,7 +88,7 @@ let x2 = >OverWriteAttr : typeof OverWriteAttr >x : 3 >3 : 3 ->overwrite : "hi" +>overwrite : string >obj1 : { x: 2; } >{y: true} : { y: true; } >y : true @@ -98,7 +98,7 @@ let x3 = x3 : JSX.Element > : JSX.Element >OverWriteAttr : typeof OverWriteAttr ->overwrite : "hi" +>overwrite : string >obj1 : { x: 2; } >x : 3 >3 : 3 diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution12.types b/tests/baselines/reference/tsxSpreadAttributesResolution12.types index 244a66e5d06bc..ff6f7140d7507 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution12.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution12.types @@ -72,14 +72,14 @@ let x = >OverWriteAttr : typeof OverWriteAttr >obj : {} >y : true ->overwrite : "hi" +>overwrite : string >obj1 : { x: 2; } let x1 = >x1 : JSX.Element > : JSX.Element >OverWriteAttr : typeof OverWriteAttr ->overwrite : "hi" +>overwrite : string >obj1 : { x: 2; } >x : 3 >3 : 3 @@ -99,7 +99,7 @@ let x3 = >x3 : JSX.Element > : JSX.Element >OverWriteAttr : typeof OverWriteAttr ->overwrite : "hi" +>overwrite : string >obj1 : { x: 2; } >{y: true} : { y: true; } >y : true diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution13.types b/tests/baselines/reference/tsxSpreadAttributesResolution13.types index 74f9788ca805a..0ad324c25b18f 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution13.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution13.types @@ -39,7 +39,7 @@ export default function Component(props: ComponentProps) { > : JSX.Element >ChildComponent : ({ property1 }: AnotherComponentProps) => JSX.Element >props : ComponentProps ->property1 : "NewString" +>property1 : string } } diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution15.types b/tests/baselines/reference/tsxSpreadAttributesResolution15.types index 0a7183b8f0d51..152ad3f696eac 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution15.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution15.types @@ -25,7 +25,7 @@ export default function Component(props: ComponentProps) { >AnotherComponent : ({ property1 }: AnotherComponentProps) => JSX.Element >props : ComponentProps >property2 : true ->AnotherProperty1 : "hi" +>AnotherProperty1 : string ); } diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution2.types b/tests/baselines/reference/tsxSpreadAttributesResolution2.types index 80c94ada9ffc2..21710567b0879 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution2.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution2.types @@ -71,5 +71,5 @@ let w1 = ; >5 : 5 >y : "2" >"2" : "2" ->X : "hi" +>X : string diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution3.types b/tests/baselines/reference/tsxSpreadAttributesResolution3.types index 2363ef7b7ccc4..13ea6343298f1 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution3.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution3.types @@ -54,7 +54,7 @@ let y = ; >y : JSX.Element > : JSX.Element >Poisoned : typeof Poisoned ->x : "hi" ->y : 2 +>x : string +>y : number >2 : 2 diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution6.types b/tests/baselines/reference/tsxSpreadAttributesResolution6.types index d5e40bdf278d8..b45fd73f2665f 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution6.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution6.types @@ -35,7 +35,7 @@ let x = >x : JSX.Element > : JSX.Element >TextComponent : typeof TextComponent ->editable : true +>editable : boolean >true : true const textProps: TextProps = { diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution8.types b/tests/baselines/reference/tsxSpreadAttributesResolution8.types index 7f07213aeaba7..ad6caef41cb48 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution8.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution8.types @@ -64,7 +64,7 @@ let x = >OverWriteAttr : typeof OverWriteAttr >obj : {} >y : true ->overwrite : "hi" +>overwrite : string >obj1 : { x: number; } let x1 = diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types index bfec805860bdb..cb1908845ddfd 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types @@ -46,35 +46,35 @@ const c1 = >c1 : JSX.Element > : JSX.Element >OneThing : { (k: { yxx: string; }): JSX.Element; (k: { yxx1: string; children: string; }): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; (l: { yy: number; yy1: string; yy2: boolean; }): JSX.Element; (l1: { data: string; "data-prop": boolean; }): JSX.Element; } ->yxx : "ok" +>yxx : string const c2 = >c2 : JSX.Element > : JSX.Element >OneThing : { (k: { yxx: string; }): JSX.Element; (k: { yxx1: string; children: string; }): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; (l: { yy: number; yy1: string; yy2: boolean; }): JSX.Element; (l1: { data: string; "data-prop": boolean; }): JSX.Element; } ->yy : 100 +>yy : number >100 : 100 ->yy1 : "hello" +>yy1 : string const c3 = >c3 : JSX.Element > : JSX.Element >OneThing : { (k: { yxx: string; }): JSX.Element; (k: { yxx1: string; children: string; }): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; (l: { yy: number; yy1: string; yy2: boolean; }): JSX.Element; (l1: { data: string; "data-prop": boolean; }): JSX.Element; } ->yxx : "hello" +>yxx : string >ignore-prop : true const c4 = >c4 : JSX.Element > : JSX.Element >OneThing : { (k: { yxx: string; }): JSX.Element; (k: { yxx1: string; children: string; }): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; (l: { yy: number; yy1: string; yy2: boolean; }): JSX.Element; (l1: { data: string; "data-prop": boolean; }): JSX.Element; } ->data : "hello" +>data : string >data-prop : true const c5 = Hello >c5 : JSX.Element >Hello : JSX.Element >OneThing : { (k: { yxx: string; }): JSX.Element; (k: { yxx1: string; children: string; }): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; (l: { yy: number; yy1: string; yy2: boolean; }): JSX.Element; (l1: { data: string; "data-prop": boolean; }): JSX.Element; } ->yxx1 : "ok" +>yxx1 : string >OneThing : { (k: { yxx: string; }): JSX.Element; (k: { yxx1: string; children: string; }): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; (l: { yy: number; yy1: string; yy2: boolean; }): JSX.Element; (l1: { data: string; "data-prop": boolean; }): JSX.Element; } @@ -120,32 +120,32 @@ const d2 = ; >d2 : JSX.Element > : JSX.Element >TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } ->extra-data : "hello" +>extra-data : string const d3 = ; >d3 : JSX.Element > : JSX.Element >TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } ->extra-data : "hello" ->yy : "hihi" +>extra-data : string +>yy : string const d4 = ; >d4 : JSX.Element > : JSX.Element >TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } ->extra-data : "hello" ->yy : 9 +>extra-data : string +>yy : number >9 : 9 ->direction : 10 +>direction : number >10 : 10 const d5 = ; >d5 : JSX.Element > : JSX.Element >TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } ->extra-data : "hello" ->yy : "hello" ->name : "Bob" +>extra-data : string +>yy : string +>name : string declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element; @@ -175,14 +175,14 @@ const e3 = >e3 : JSX.Element > : JSX.Element >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } ->y1 : "hello" +>y1 : string const e4 = >e4 : JSX.Element > : JSX.Element >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } ->y1 : "hello" ->y2 : 1000 +>y1 : string +>y2 : number >1000 : 1000 const e5 = @@ -198,7 +198,7 @@ const e6 = >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } >y1 : true >y3 : true ->y2 : 10 +>y2 : number >10 : 10 const e2 = diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload2.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload2.types index fbf06619cf2ec..d1cc5774447df 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload2.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload2.types @@ -82,7 +82,7 @@ const c5 = > : JSX.Element >OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; } >obj1 : { yy: boolean; } ->yy : 42 +>yy : number >42 : 42 >{yy1: "hi"} : { yy1: string; } >yy1 : string @@ -111,7 +111,7 @@ const c8 = >c8 : JSX.Element > : JSX.Element >OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; } ->ignore-prop : 100 +>ignore-prop : number >100 : 100 const c9 = ; @@ -126,5 +126,5 @@ const c10 = ; > : JSX.Element >OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; } >obj2 : { yy: number; "ignore-prop": string; } ->yy1 : "boo" +>yy1 : string diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload3.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload3.types index c1f08044d3c1f..6574f46f483ec 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload3.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload3.types @@ -33,9 +33,9 @@ const two2 = ; >two2 : JSX.Element > : JSX.Element >ZeroThingOrTwoThing : { (): JSX.Element; (l: { yy: number; yy1: string; }, context: Context): JSX.Element; } ->yy : 100 +>yy : number >100 : 100 ->yy1 : "hello" +>yy1 : string const two3 = ; // it is just any so we allow it to pass through >two3 : JSX.Element @@ -47,7 +47,7 @@ const two4 = ; // it is just any so >two4 : JSX.Element > : JSX.Element >ZeroThingOrTwoThing : { (): JSX.Element; (l: { yy: number; yy1: string; }, context: Context): JSX.Element; } ->yy : 1000 +>yy : number >1000 : 1000 >obj2 : any @@ -56,7 +56,7 @@ const two5 = ; // it is just any so > : JSX.Element >ZeroThingOrTwoThing : { (): JSX.Element; (l: { yy: number; yy1: string; }, context: Context): JSX.Element; } >obj2 : any ->yy : 1000 +>yy : number >1000 : 1000 declare function ThreeThing(l: {y1: string}): JSX.Element; @@ -89,21 +89,21 @@ const three1 = ; >three1 : JSX.Element > : JSX.Element >ThreeThing : { (l: { y1: string; }): JSX.Element; (l: { y2: string; }): JSX.Element; (l: { yy: number; yy1: string; }, context: Context, updater: any): JSX.Element; } ->yy : 99 +>yy : number >99 : 99 ->yy1 : "hello world" +>yy1 : string const three2 = ; >three2 : JSX.Element > : JSX.Element >ThreeThing : { (l: { y1: string; }): JSX.Element; (l: { y2: string; }): JSX.Element; (l: { yy: number; yy1: string; }, context: Context, updater: any): JSX.Element; } ->y2 : "Bye" +>y2 : string const three3 = ; // it is just any so we allow it to pass through >three3 : JSX.Element > : JSX.Element >ThreeThing : { (l: { y1: string; }): JSX.Element; (l: { y2: string; }): JSX.Element; (l: { yy: number; yy1: string; }, context: Context, updater: any): JSX.Element; } >obj2 : any ->y2 : 10 +>y2 : number >10 : 10 diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.types index fb4cc66bd9cd0..fe265c5c4d063 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.types @@ -41,7 +41,7 @@ const c1 = ; // missing property; >c1 : JSX.Element > : JSX.Element >OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; } ->yy : 10 +>yy : number >10 : 10 const c2 = ; // type incompatible; @@ -65,7 +65,7 @@ const c4 = ; // extra property; > : JSX.Element >OneThing : { (): JSX.Element; (l: { yy: number; yy1: string; }): JSX.Element; } >obj : { yy: number; yy1: string; } ->y1 : 10000 +>y1 : number >10000 : 10000 const c5 = ; // type incompatible; @@ -118,8 +118,8 @@ const d2 = >d2 : JSX.Element > : JSX.Element >TestingOneThing : { (j: { "extra-data": string; }): JSX.Element; (n: { yy: string; direction?: number; }): JSX.Element; } ->yy : "hello" ->direction : "left" +>yy : string +>direction : string declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element; >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } @@ -155,14 +155,14 @@ const e1 = > : JSX.Element >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } >y1 : true ->y3 : "hello" +>y3 : string const e2 = >e2 : JSX.Element > : JSX.Element >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } ->y1 : "hello" ->y2 : 1000 +>y1 : string +>y2 : number >1000 : 1000 >y3 : true @@ -170,17 +170,17 @@ const e3 = >e3 : JSX.Element > : JSX.Element >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } ->y1 : "hello" ->y2 : 1000 +>y1 : string +>y2 : number >1000 : 1000 ->children : "hi" +>children : string const e4 = Hi >e4 : JSX.Element >Hi : JSX.Element >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } ->y1 : "hello" ->y2 : 1000 +>y1 : string +>y2 : number >1000 : 1000 >TestingOptional : { (a: { y1?: string; y2?: number; }): JSX.Element; (a: { y1?: string; y2?: number; children: JSX.Element; }): JSX.Element; (a: { y1: boolean; y2?: number; y3: boolean; }): JSX.Element; } diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload5.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload5.types index 2bd3281eb2e21..b60a5a2d3f03e 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload5.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload5.types @@ -134,7 +134,7 @@ const b0 = {}}>GO; // ex >b0 : JSX.Element >{}}>GO : JSX.Element >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } ->to : "/some/path" +>to : string >onClick : (e: React.MouseEvent) => void >(e)=>{} : (e: React.MouseEvent) => void >e : React.MouseEvent @@ -194,7 +194,7 @@ const b6 = ; // incorrec >{ onClick(e: any){} } : { onClick(e: any): void; } >onClick : (e: any) => void >e : any ->children : 10 +>children : number >10 : 10 const b7 = ; // incorrect type for optional attribute @@ -204,7 +204,7 @@ const b7 = ; >{ onClick(e: any){} } : { onClick(e: any): void; } >onClick : (e: any) => void >e : any ->children : "hello" +>children : string >className : true const b8 = ; // incorrect type for specified hyphanated name diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload6.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload6.types index 6272288c035e9..6f7f04e3cf3b3 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload6.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload6.types @@ -123,7 +123,7 @@ const b0 = GO; >b0 : JSX.Element >GO : JSX.Element >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } ->to : "/some/path" +>to : string >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } const b1 = {}}>Hello world; @@ -161,7 +161,7 @@ const b5 = ; // should pick the seco > : JSX.Element >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } >obj1 : any ->to : "/to/somewhere" +>to : string const b6 = ; >b6 : JSX.Element @@ -193,7 +193,7 @@ const b9 = GO; >b9 : JSX.Element >GO : JSX.Element >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } ->to : "/some/path" +>to : string >extra-prop : true >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } @@ -201,8 +201,8 @@ const b10 = ; >b10 : JSX.Element > : JSX.Element >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } ->to : "/some/path" ->children : "hi" +>to : string +>children : string >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } const b11 = {}} className="hello" data-format>Hello world; @@ -212,7 +212,7 @@ const b11 = {}} className="hello" data-format>Hello >onClick : (e: React.MouseEvent) => void >(e) => {} : (e: React.MouseEvent) => void >e : React.MouseEvent ->className : "hello" +>className : string >data-format : true >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } @@ -220,7 +220,7 @@ const b12 = >b12 : JSX.Element > : JSX.Element >MainButton : { (buttonProps: ButtonProps): JSX.Element; (linkProps: LinkProps): JSX.Element; (hyphenProps: HyphenProps): JSX.Element; } ->data-format : "Hello world" +>data-format : string diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter1.types b/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter1.types index 8c545b19e089f..ddbeb8deca017 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter1.types @@ -33,5 +33,5 @@ let i1 = ; >i1 : JSX.Element > : JSX.Element >MyComponent : (attr: T) => JSX.Element ->values : "Hello" +>values : string diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter2.types b/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter2.types index d43e7419d3400..fe9439447f453 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter2.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentWithDefaultTypeParameter2.types @@ -28,6 +28,6 @@ let i1 = ; >i1 : JSX.Element > : JSX.Element >MyComponent1 : (attr: T) => JSX.Element ->values : 5 +>values : number >5 : 5 diff --git a/tests/baselines/reference/tsxStatelessFunctionComponents1.types b/tests/baselines/reference/tsxStatelessFunctionComponents1.types index ffea243867519..ffd52cb497815 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponents1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponents1.types @@ -45,13 +45,13 @@ let a = ; >a : JSX.Element > : JSX.Element >Greet : (x: { name: string; }) => JSX.Element ->name : "world" +>name : string let a1 = ; >a1 : JSX.Element > : JSX.Element >Greet : (x: { name: string; }) => JSX.Element ->name : "world" +>name : string >extra-prop : true // Error @@ -59,7 +59,7 @@ let b = ; >b : JSX.Element > : JSX.Element >Greet : (x: { name: string; }) => JSX.Element ->naaame : "world" +>naaame : string // OK let c = ; @@ -78,14 +78,14 @@ let d = ; >d : JSX.Element > : JSX.Element >Meet : ({ name }: { name?: string; }) => JSX.Element ->name : "me" +>name : string // Error let e = ; >e : JSX.Element > : JSX.Element >Meet : ({ name }: { name?: string; }) => JSX.Element ->name : 42 +>name : number >42 : 42 // Error @@ -93,21 +93,21 @@ let f = ; >f : JSX.Element > : JSX.Element >Meet : ({ name }: { name?: string; }) => JSX.Element ->naaaaaaame : "no" +>naaaaaaame : string // OK let g = ; >g : JSX.Element > : JSX.Element >MeetAndGreet : (k: { "prop-name": string; }) => JSX.Element ->prop-name : "Bob" +>prop-name : string // Error let h = ; >h : JSX.Element > : JSX.Element >MeetAndGreet : (k: { "prop-name": string; }) => JSX.Element ->extra-prop-name : "World" +>extra-prop-name : string // Error let i = diff --git a/tests/baselines/reference/tsxStatelessFunctionComponents2.types b/tests/baselines/reference/tsxStatelessFunctionComponents2.types index f033d50fd721b..05fe1a8897bc4 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponents2.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponents2.types @@ -44,14 +44,14 @@ let b = ; >b : JSX.Element > : JSX.Element >Greet : (x: { name?: string; }) => JSX.Element ->key : "k" +>key : string // Error - not allowed to specify 'ref' on SFCs let c = ; >c : JSX.Element > : JSX.Element >Greet : (x: { name?: string; }) => JSX.Element ->ref : "myRef" +>ref : string // OK - ref is valid for classes @@ -103,7 +103,7 @@ let g = ; >g : JSX.Element > : JSX.Element >BigGreeter : typeof BigGreeter ->key : 100 +>key : number >100 : 100 // OK - contextually typed intrinsic ref callback parameter diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types index 2fbb2d333ef6c..2758ca7e0df1a 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments1.types @@ -41,7 +41,7 @@ function Baz(key1: T, value: U) { >key1 : T >value : U >value : U ->key : "Component" +>key : string } declare function Link(l: {func: (arg: U)=>void}): JSX.Element; diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.types b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.types index 808fe38ee09d5..851839ea921b6 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.types @@ -33,7 +33,7 @@ function Bar(arg: T) { > : JSX.Element >ComponentSpecific1 : (l: { prop: U; "ignore-prop": string; }) => JSX.Element >arg : T ->ignore-prop : 10 +>ignore-prop : number >10 : 10 } diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments3.types b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments3.types index 8bc938a48618a..aa38d2ccf8ac5 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments3.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments3.types @@ -48,7 +48,7 @@ function Baz(arg1: T, a > : JSX.Element >OverloadComponent : { (): JSX.Element; (attr: { b: U; a?: string; "ignore-prop": boolean; }): JSX.Element; (attr: { b: U; a: T; }): JSX.Element; } >arg1 : T ->a : "hello" +>a : string >ignore-prop : true let a1 = ; @@ -56,7 +56,7 @@ function Baz(arg1: T, a > : JSX.Element >OverloadComponent : { (): JSX.Element; (attr: { b: U; a?: string; "ignore-prop": boolean; }): JSX.Element; (attr: { b: U; a: T; }): JSX.Element; } >arg2 : U ->ignore-pro : "hello world" +>ignore-pro : string let a2 = ; >a2 : JSX.Element @@ -81,7 +81,7 @@ function Baz(arg1: T, a > : JSX.Element >OverloadComponent : { (): JSX.Element; (attr: { b: U; a?: string; "ignore-prop": boolean; }): JSX.Element; (attr: { b: U; a: T; }): JSX.Element; } >arg2 : U ->ignore-prop : "hello" +>ignore-prop : string >arg1 : T let a6 = ; diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.types b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.types index 627ac387449a1..98a9c62179732 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments5.types @@ -61,14 +61,14 @@ function Bar(arg: T) { > : JSX.Element >ComponentSpecific : (l: { prop: U; }) => JSX.Element >arg : T ->ignore-prop : "hi" +>ignore-prop : string let a2 = ; // U is number >a2 : JSX.Element > : JSX.Element >ComponentSpecific1 : (l: { prop: U; "ignore-prop": number; }) => JSX.Element >arg : T ->ignore-prop : 10 +>ignore-prop : number >10 : 10 let a3 = ; // U is "hello" @@ -76,13 +76,13 @@ function Bar(arg: T) { > : JSX.Element >ComponentSpecific : (l: { prop: U; }) => JSX.Element >arg : T ->prop : "hello" +>prop : string let a4 = ; // U is "hello" >a4 : JSX.Element > : JSX.Element >ComponentSpecific : (l: { prop: U; }) => JSX.Element >arg : T ->prop1 : "hello" +>prop1 : string } diff --git a/tests/baselines/reference/tsxTypeErrors.types b/tests/baselines/reference/tsxTypeErrors.types index 1203bb4f0257a..91740cf88dea1 100644 --- a/tests/baselines/reference/tsxTypeErrors.types +++ b/tests/baselines/reference/tsxTypeErrors.types @@ -4,14 +4,14 @@ var a1 =
    ; >a1 : any >
    : any >div : any ->id : "foo" +>id : string // A built-in element with a mistyped property (error) var a2 = >a2 : any > : any >img : any ->srce : "foo.jpg" +>srce : string // A built-in element with a badly-typed attribute value (error) var thing = { oops: 100 }; @@ -32,7 +32,7 @@ var e1 = >e1 : any > : any >imag : any ->src : "bar.jpg" +>src : string // A custom type class MyClass { @@ -60,7 +60,7 @@ var b1 = ; >b1 : any > : any >MyClass : typeof MyClass ->reqd : true +>reqd : boolean >true : true // Mistyped attribute member diff --git a/tests/baselines/reference/tsxUnionElementType2.types b/tests/baselines/reference/tsxUnionElementType2.types index 822ba7f0028ee..3b2df619596a8 100644 --- a/tests/baselines/reference/tsxUnionElementType2.types +++ b/tests/baselines/reference/tsxUnionElementType2.types @@ -34,6 +34,6 @@ var SFCComp = SFC1 || SFC2; > : JSX.Element >SFCComp : ((prop: { x: number; }) => JSX.Element) | ((prop: { x: boolean; }) => JSX.Element) ->x : "hi" +>x : string >"hi" : "hi" diff --git a/tests/baselines/reference/tsxUnionElementType3.types b/tests/baselines/reference/tsxUnionElementType3.types index 8f3ad7056bd26..5a797ea483b59 100644 --- a/tests/baselines/reference/tsxUnionElementType3.types +++ b/tests/baselines/reference/tsxUnionElementType3.types @@ -85,7 +85,7 @@ let a = ; >a : JSX.Element > : JSX.Element >RCComp : typeof RC1 | typeof RC2 ->x : "Hi" +>x : string let a1 = ; >a1 : JSX.Element @@ -96,7 +96,7 @@ let a2 = ; >a2 : JSX.Element > : JSX.Element >EmptyRCComp : typeof RC3 ->data-prop : "hello" +>data-prop : string let b = >b : JSX.Element @@ -107,5 +107,5 @@ let c = >c : JSX.Element > : JSX.Element >PartRCComp : typeof RC4 ->data-extra : "hello" +>data-extra : string diff --git a/tests/baselines/reference/tsxUnionElementType4.types b/tests/baselines/reference/tsxUnionElementType4.types index 9d60f0462fd42..c0961eb6d1644 100644 --- a/tests/baselines/reference/tsxUnionElementType4.types +++ b/tests/baselines/reference/tsxUnionElementType4.types @@ -91,7 +91,7 @@ let b = >b : JSX.Element > : JSX.Element >PartRCComp : typeof RC4 ->x : 10 +>x : number >10 : 10 let c = ; diff --git a/tests/baselines/reference/tsxUnionElementType6.types b/tests/baselines/reference/tsxUnionElementType6.types index 5b7a1c0a5031f..db36bad01f063 100644 --- a/tests/baselines/reference/tsxUnionElementType6.types +++ b/tests/baselines/reference/tsxUnionElementType6.types @@ -54,7 +54,7 @@ let b = ; >b : JSX.Element > : JSX.Element >SFC2AndEmptyComp : (prop: { x: boolean; }) => JSX.Element ->x : "hi" +>x : string let c = ; >c : JSX.Element From be498533f5ba3b235602dd794a97a8745280efe3 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 15 Dec 2017 10:33:22 -0800 Subject: [PATCH 5/7] Restore jsdoc tag interpretation --- src/compiler/checker.ts | 32 +++++++++---------- src/compiler/utilities.ts | 2 +- .../checkJsdocTypeTagOnObjectProperty1.types | 6 ++-- .../checkJsdocTypeTagOnObjectProperty2.types | 8 ++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b7f242b1c5919..0bfd35ff9de89 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4634,6 +4634,13 @@ namespace ts { return isPrivateWithinAmbient(memberDeclaration); } + function tryGetTypeFromEffectiveTypeNode(declaration: Declaration) { + const typeNode = getEffectiveTypeAnnotationNode(declaration); + if (typeNode) { + return getTypeFromTypeNode(typeNode); + } + } + function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.type) { @@ -4668,30 +4675,23 @@ namespace ts { declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { type = getWidenedTypeFromJSSpecialPropertyDeclarations(symbol); } - else if (isJSDocPropertyTag(declaration)) { - type = anyType; // TODO: Mimics old behavior from incorrect usage of getWidenedTypeForVariableLikeDeclaration, but seems incorrect - } - else if (isPropertyAccessExpression(declaration) || isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration)) { - // TODO: Mimics old behavior from incorrect usage of getWidenedTypeForVariableLikeDeclaration, but seems lacking - const typeNode = getEffectiveTypeAnnotationNode(declaration); - if (typeNode) { - type = getTypeFromTypeNode(typeNode); - } - else { - type = anyType; - } + else if (isJSDocPropertyTag(declaration) + || isPropertyAccessExpression(declaration) + || isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration)) { + // TODO: Mimics old behavior from incorrect usage of getWidenedTypeForVariableLikeDeclaration, but seems incorrect + type = tryGetTypeFromEffectiveTypeNode(declaration) || anyType; } else if (isPropertyAssignment(declaration)) { - type = checkPropertyAssignment(declaration); + type = tryGetTypeFromEffectiveTypeNode(declaration) || checkPropertyAssignment(declaration); } else if (isJsxAttribute(declaration)) { - type = checkJsxAttribute(declaration); + type = tryGetTypeFromEffectiveTypeNode(declaration) || checkJsxAttribute(declaration); } else if (isShorthandPropertyAssignment(declaration)) { - type = checkExpressionForMutableLocation(declaration.name, CheckMode.Normal); + type = tryGetTypeFromEffectiveTypeNode(declaration) || checkExpressionForMutableLocation(declaration.name, CheckMode.Normal); } else if (isObjectLiteralMethod(declaration)) { - type = checkObjectLiteralMethod(declaration, CheckMode.Normal); + type = tryGetTypeFromEffectiveTypeNode(declaration) || checkObjectLiteralMethod(declaration, CheckMode.Normal); } else if (isParameter(declaration) || isPropertyDeclaration(declaration) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 91e63019f30a6..87526f5988216 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2816,7 +2816,7 @@ namespace ts { * Gets the effective type annotation of a variable, parameter, or property. If the node was * parsed in a JavaScript file, gets the type annotation from JSDoc. */ - export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration | Expression, checkJSDoc?: boolean): TypeNode | undefined { + export function getEffectiveTypeAnnotationNode(node: Node, checkJSDoc?: boolean): TypeNode | undefined { if (hasType(node)) { return node.type; } diff --git a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.types b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.types index 60aa4bc0a8000..72c5c55228e0d 100644 --- a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.types +++ b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.types @@ -10,12 +10,12 @@ const obj = { /** @type {string|undefined} */ foo: undefined, ->foo : undefined +>foo : string | undefined >undefined : undefined /** @type {string|undefined} */ bar: "42", ->bar : string +>bar : string | undefined >"42" : "42" /** @type {function(number): number} */ @@ -42,7 +42,7 @@ const obj = { /** @type {function(number): number} */ arrowFunc: (num) => num + 42 ->arrowFunc : (num: any) => any +>arrowFunc : (arg0: number) => number >(num) => num + 42 : (num: any) => any >num : any >num + 42 : any diff --git a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types index 8f16ebfae5d3f..443826c7aeb58 100644 --- a/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types +++ b/tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.types @@ -9,7 +9,7 @@ const obj = { /** @type {string|undefined} */ bar: 42, ->bar : number +>bar : string | undefined >42 : 42 /** @type {function(number): number} */ @@ -23,14 +23,14 @@ const obj = { }, /** @type {function(number): number} */ method2: (n1) => "lol", ->method2 : (n1: any) => string +>method2 : (arg0: number) => number >(n1) => "lol" : (n1: any) => string >n1 : any >"lol" : "lol" /** @type {function(number): number} */ arrowFunc: (num="0") => num + 42, ->arrowFunc : (num?: string) => string +>arrowFunc : (arg0: number) => number >(num="0") => num + 42 : (num?: string) => string >num : string >"0" : "0" @@ -40,7 +40,7 @@ const obj = { /** @type {string} */ lol ->lol : undefined +>lol : string } lol = "string" >lol = "string" : "string" From f947fbfbbd073a03c8ce24bd1210e4840ef99e54 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 15 Dec 2017 10:40:26 -0800 Subject: [PATCH 6/7] Clean up some code, revert fourslash tests --- src/compiler/checker.ts | 5 ++--- tests/cases/fourslash/tsxQuickInfo3.ts | 2 +- tests/cases/fourslash/tsxQuickInfo4.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0bfd35ff9de89..1eae08ae99175 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4394,9 +4394,8 @@ namespace ts { const isOptional = !isBindingElement(declaration) && !isVariableDeclaration(declaration) && !!declaration.questionToken && includeOptionality; // Use type from type annotation if one is present - const typeNode = getEffectiveTypeAnnotationNode(declaration); - if (typeNode) { - const declaredType = getTypeFromTypeNode(typeNode); + const declaredType = tryGetTypeFromEffectiveTypeNode(declaration); + if (declaredType) { return addOptionality(declaredType, isOptional); } diff --git a/tests/cases/fourslash/tsxQuickInfo3.ts b/tests/cases/fourslash/tsxQuickInfo3.ts index 5130627097302..614ffa878ef09 100644 --- a/tests/cases/fourslash/tsxQuickInfo3.ts +++ b/tests/cases/fourslash/tsxQuickInfo3.ts @@ -24,7 +24,7 @@ verify.quickInfos({ 1: "class Opt", - 2: "(JSX attribute) propx: 2", + 2: "(JSX attribute) propx: number", 3: "const obj1: OptionProp", 4: "(JSX attribute) propx: true" }); diff --git a/tests/cases/fourslash/tsxQuickInfo4.ts b/tests/cases/fourslash/tsxQuickInfo4.ts index bc322d2f89287..d9f566571aafd 100644 --- a/tests/cases/fourslash/tsxQuickInfo4.ts +++ b/tests/cases/fourslash/tsxQuickInfo4.ts @@ -48,7 +48,7 @@ verify.quickInfos({ 1: "function MainButton(linkProps: LinkProps): any (+1 overload)", - 2: "(JSX attribute) to: \"/some/path\"", + 2: "(JSX attribute) to: string", 3: "function MainButton(buttonProps: ButtonProps): any (+1 overload)", 4: "(JSX attribute) onClick: () => void", 5: "(JSX attribute) extra-prop: true" From 07c7c6d2e9b2459a7cf7e0a3ee12e12a4a34c339 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 15 Dec 2017 14:17:01 -0800 Subject: [PATCH 7/7] Cleanup types used by PR feedback --- src/compiler/checker.ts | 2 +- src/compiler/types.ts | 13 +++---------- src/compiler/utilities.ts | 8 ++++---- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1eae08ae99175..baa6cb0a4eef1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4216,7 +4216,7 @@ namespace ts { // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been // assigned by contextual typing. - function getTypeForBindingElementParent(node: BindingElement["parent"]["parent"]) { + function getTypeForBindingElementParent(node: BindingElementGrandparent) { const symbol = getSymbolOfNode(node); return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5283dc974967d..51465a6baf569 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -584,11 +584,6 @@ namespace ts { | JSDocFunctionType | EndOfFileToken; - /* @internal */ - export interface TypeContainer { - type?: TypeNode; - } - export type HasType = | SignatureDeclaration | VariableDeclaration @@ -607,11 +602,6 @@ namespace ts { | JSDocOptionalType | JSDocVariadicType; - /* @internal */ - export interface InitializerContainer { - initializer?: Expression; - } - export type HasInitializer = | HasExpressionInitializer | ForStatement @@ -837,6 +827,9 @@ namespace ts { initializer?: Expression; // Optional initializer } + /*@internal*/ + export type BindingElementGrandparent = BindingElement["parent"]["parent"]; + export interface PropertySignature extends TypeElement, JSDocContainer { kind: SyntaxKind.PropertySignature; name: PropertyName; // Declared property name diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 87526f5988216..2a2561907f780 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -784,7 +784,7 @@ namespace ts { case SyntaxKind.PropertySignature: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - return node === (parent as Node & { type: Node }).type; + return node === (parent as HasType).type; case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -1340,7 +1340,7 @@ namespace ts { case SyntaxKind.EnumMember: case SyntaxKind.PropertyAssignment: case SyntaxKind.BindingElement: - return (parent as Node & { initializer: Node }).initializer === node; + return (parent as HasInitializer).initializer === node; case SyntaxKind.ExpressionStatement: case SyntaxKind.IfStatement: case SyntaxKind.DoStatement: @@ -5816,13 +5816,13 @@ namespace ts { /** True if has type node attached to it. */ /* @internal */ export function hasType(node: Node): node is HasType { - return !!(node as TypeContainer).type; + return !!(node as HasType).type; } /** True if has initializer node attached to it. */ /* @internal */ export function hasInitializer(node: Node): node is HasInitializer { - return !!(node as InitializerContainer).initializer; + return !!(node as HasInitializer).initializer; } /** True if has initializer node attached to it. */