Skip to content

Commit 1e9518c

Browse files
TypeScript Botweswigham
TypeScript Bot
andauthored
Cherry-pick PR #41758 into release-4.1 (#41862)
Component commits: 0d61b14 addImplementationSuccessElaboration admits declarations with no symbol Co-authored-by: Wesley Wigham <[email protected]>
1 parent abf8815 commit 1e9518c

6 files changed

+122
-3
lines changed

src/compiler/checker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27448,9 +27448,9 @@ namespace ts {
2744827448
const oldCandidateForArgumentArityError = candidateForArgumentArityError;
2744927449
const oldCandidateForTypeArgumentError = candidateForTypeArgumentError;
2745027450

27451-
const declCount = length(failed.declaration?.symbol.declarations);
27452-
const isOverload = declCount > 1;
27453-
const implDecl = isOverload ? find(failed.declaration?.symbol.declarations || emptyArray, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
27451+
const failedSignatureDeclarations = failed.declaration?.symbol?.declarations || emptyArray;
27452+
const isOverload = failedSignatureDeclarations.length > 1;
27453+
const implDecl = isOverload ? find(failedSignatureDeclarations, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
2745427454
if (implDecl) {
2745527455
const candidate = getSignatureFromDeclaration(implDecl as FunctionLikeDeclaration);
2745627456
const isSingleNonGenericCandidate = !candidate.typeParameters;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx(10,29): error TS2322: Type '{}' is not assignable to type 'LibraryManagedAttributes<Tag, DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>'.
2+
3+
4+
==== tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx (1 errors) ====
5+
/// <reference path="/.lib/react16.d.ts" />
6+
7+
import * as React from "react";
8+
9+
type Tags = "span" | "div";
10+
11+
export const Hoc = <Tag extends Tags>(
12+
TagElement: Tag,
13+
): React.SFC => {
14+
const Component = () => <TagElement />;
15+
~~~~~~~~~~
16+
!!! error TS2322: Type '{}' is not assignable to type 'LibraryManagedAttributes<Tag, DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>'.
17+
return Component;
18+
};
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [jsxCallElaborationCheckNoCrash1.tsx]
2+
/// <reference path="/.lib/react16.d.ts" />
3+
4+
import * as React from "react";
5+
6+
type Tags = "span" | "div";
7+
8+
export const Hoc = <Tag extends Tags>(
9+
TagElement: Tag,
10+
): React.SFC => {
11+
const Component = () => <TagElement />;
12+
return Component;
13+
};
14+
15+
16+
//// [jsxCallElaborationCheckNoCrash1.js]
17+
"use strict";
18+
/// <reference path="react16.d.ts" />
19+
exports.__esModule = true;
20+
exports.Hoc = void 0;
21+
var React = require("react");
22+
var Hoc = function (TagElement) {
23+
var Component = function () { return React.createElement(TagElement, null); };
24+
return Component;
25+
};
26+
exports.Hoc = Hoc;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
4+
import * as React from "react";
5+
>React : Symbol(React, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 6))
6+
7+
type Tags = "span" | "div";
8+
>Tags : Symbol(Tags, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 31))
9+
10+
export const Hoc = <Tag extends Tags>(
11+
>Hoc : Symbol(Hoc, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 12))
12+
>Tag : Symbol(Tag, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 20))
13+
>Tags : Symbol(Tags, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 31))
14+
15+
TagElement: Tag,
16+
>TagElement : Symbol(TagElement, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 38))
17+
>Tag : Symbol(Tag, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 20))
18+
19+
): React.SFC => {
20+
>React : Symbol(React, Decl(jsxCallElaborationCheckNoCrash1.tsx, 2, 6))
21+
>SFC : Symbol(React.SFC, Decl(react16.d.ts, 400, 9))
22+
23+
const Component = () => <TagElement />;
24+
>Component : Symbol(Component, Decl(jsxCallElaborationCheckNoCrash1.tsx, 9, 8))
25+
>TagElement : Symbol(TagElement, Decl(jsxCallElaborationCheckNoCrash1.tsx, 6, 38))
26+
27+
return Component;
28+
>Component : Symbol(Component, Decl(jsxCallElaborationCheckNoCrash1.tsx, 9, 8))
29+
30+
};
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/jsxCallElaborationCheckNoCrash1.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
4+
import * as React from "react";
5+
>React : typeof React
6+
7+
type Tags = "span" | "div";
8+
>Tags : Tags
9+
10+
export const Hoc = <Tag extends Tags>(
11+
>Hoc : <Tag extends Tags>(TagElement: Tag) => React.SFC
12+
><Tag extends Tags>( TagElement: Tag,): React.SFC => { const Component = () => <TagElement />; return Component;} : <Tag extends Tags>(TagElement: Tag) => React.SFC
13+
14+
TagElement: Tag,
15+
>TagElement : Tag
16+
17+
): React.SFC => {
18+
>React : any
19+
20+
const Component = () => <TagElement />;
21+
>Component : () => JSX.Element
22+
>() => <TagElement /> : () => JSX.Element
23+
><TagElement /> : JSX.Element
24+
>TagElement : Tag
25+
26+
return Component;
27+
>Component : () => JSX.Element
28+
29+
};
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @jsx: react
2+
/// <reference path="/.lib/react16.d.ts" />
3+
4+
import * as React from "react";
5+
6+
type Tags = "span" | "div";
7+
8+
export const Hoc = <Tag extends Tags>(
9+
TagElement: Tag,
10+
): React.SFC => {
11+
const Component = () => <TagElement />;
12+
return Component;
13+
};

0 commit comments

Comments
 (0)