Skip to content

Commit

Permalink
Cherry-pick PR #41758 into release-4.1 (#41862)
Browse files Browse the repository at this point in the history
Component commits:
0d61b14 addImplementationSuccessElaboration admits declarations with no symbol

Co-authored-by: Wesley Wigham <[email protected]>
  • Loading branch information
TypeScript Bot and weswigham authored Dec 9, 2020
1 parent abf8815 commit 1e9518c
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27448,9 +27448,9 @@ namespace ts {
const oldCandidateForArgumentArityError = candidateForArgumentArityError;
const oldCandidateForTypeArgumentError = candidateForTypeArgumentError;

const declCount = length(failed.declaration?.symbol.declarations);
const isOverload = declCount > 1;
const implDecl = isOverload ? find(failed.declaration?.symbol.declarations || emptyArray, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
const failedSignatureDeclarations = failed.declaration?.symbol?.declarations || emptyArray;
const isOverload = failedSignatureDeclarations.length > 1;
const implDecl = isOverload ? find(failedSignatureDeclarations, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
if (implDecl) {
const candidate = getSignatureFromDeclaration(implDecl as FunctionLikeDeclaration);
const isSingleNonGenericCandidate = !candidate.typeParameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx(10,29): error TS2322: Type '{}' is not assignable to type 'LibraryManagedAttributes<Tag, DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>'.


==== tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx (1 errors) ====
/// <reference path="/.lib/react16.d.ts" />

import * as React from "react";

type Tags = "span" | "div";

export const Hoc = <Tag extends Tags>(
TagElement: Tag,
): React.SFC => {
const Component = () => <TagElement />;
~~~~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'LibraryManagedAttributes<Tag, DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>'.
return Component;
};

26 changes: 26 additions & 0 deletions tests/baselines/reference/jsxCallElaborationCheckNoCrash1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [jsxCallElaborationCheckNoCrash1.tsx]
/// <reference path="/.lib/react16.d.ts" />

import * as React from "react";

type Tags = "span" | "div";

export const Hoc = <Tag extends Tags>(
TagElement: Tag,
): React.SFC => {
const Component = () => <TagElement />;
return Component;
};


//// [jsxCallElaborationCheckNoCrash1.js]
"use strict";
/// <reference path="react16.d.ts" />
exports.__esModule = true;
exports.Hoc = void 0;
var React = require("react");
var Hoc = function (TagElement) {
var Component = function () { return React.createElement(TagElement, null); };
return Component;
};
exports.Hoc = Hoc;
31 changes: 31 additions & 0 deletions tests/baselines/reference/jsxCallElaborationCheckNoCrash1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx ===
/// <reference path="react16.d.ts" />

import * as React from "react";
>React : Symbol(React, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 6))

type Tags = "span" | "div";
>Tags : Symbol(Tags, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 31))

export const Hoc = <Tag extends Tags>(
>Hoc : Symbol(Hoc, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 12))
>Tag : Symbol(Tag, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 20))
>Tags : Symbol(Tags, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 31))

TagElement: Tag,
>TagElement : Symbol(TagElement, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 38))
>Tag : Symbol(Tag, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 20))

): React.SFC => {
>React : Symbol(React, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 6))
>SFC : Symbol(React.SFC, Decl(react16.d.ts, 400, 9))

const Component = () => <TagElement />;
>Component : Symbol(Component, Decl(jsxCallElaborationCheckNoCrash1.tsx, 9, 8))
>TagElement : Symbol(TagElement, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 38))

return Component;
>Component : Symbol(Component, Decl(jsxCallElaborationCheckNoCrash1.tsx, 9, 8))

};

30 changes: 30 additions & 0 deletions tests/baselines/reference/jsxCallElaborationCheckNoCrash1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx ===
/// <reference path="react16.d.ts" />

import * as React from "react";
>React : typeof React

type Tags = "span" | "div";
>Tags : Tags

export const Hoc = <Tag extends Tags>(
>Hoc : <Tag extends Tags>(TagElement: Tag) => React.SFC
><Tag extends Tags>( TagElement: Tag,): React.SFC => { const Component = () => <TagElement />; return Component;} : <Tag extends Tags>(TagElement: Tag) => React.SFC

TagElement: Tag,
>TagElement : Tag

): React.SFC => {
>React : any

const Component = () => <TagElement />;
>Component : () => JSX.Element
>() => <TagElement /> : () => JSX.Element
><TagElement /> : JSX.Element
>TagElement : Tag

return Component;
>Component : () => JSX.Element

};

13 changes: 13 additions & 0 deletions tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @jsx: react
/// <reference path="/.lib/react16.d.ts" />

import * as React from "react";

type Tags = "span" | "div";

export const Hoc = <Tag extends Tags>(
TagElement: Tag,
): React.SFC => {
const Component = () => <TagElement />;
return Component;
};

0 comments on commit 1e9518c

Please sign in to comment.