Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addImplementationSuccessElaboration admits declarations with no symbol #41758

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Expand Up @@ -27483,9 +27483,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
};