Skip to content

Commit 0d61b14

Browse files
committed
addImplementationSuccessElaboration admits declarations with no symbol
1 parent d0c28ab commit 0d61b14

File tree

6 files changed

+122
-3
lines changed

6 files changed

+122
-3
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27483,9 +27483,9 @@ namespace ts {
2748327483
const oldCandidateForArgumentArityError = candidateForArgumentArityError;
2748427484
const oldCandidateForTypeArgumentError = candidateForTypeArgumentError;
2748527485

27486-
const declCount = length(failed.declaration?.symbol.declarations);
27487-
const isOverload = declCount > 1;
27488-
const implDecl = isOverload ? find(failed.declaration?.symbol.declarations || emptyArray, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
27486+
const failedSignatureDeclarations = failed.declaration?.symbol?.declarations || emptyArray;
27487+
const isOverload = failedSignatureDeclarations.length > 1;
27488+
const implDecl = isOverload ? find(failedSignatureDeclarations, d => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : undefined;
2748927489
if (implDecl) {
2749027490
const candidate = getSignatureFromDeclaration(implDecl as FunctionLikeDeclaration);
2749127491
const isSingleNonGenericCandidate = !candidate.typeParameters;
Lines changed: 19 additions & 0 deletions
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+
Lines changed: 26 additions & 0 deletions
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;
Lines changed: 31 additions & 0 deletions
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+
Lines changed: 30 additions & 0 deletions
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+
Lines changed: 13 additions & 0 deletions
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)