-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: 4.1.2
Search Terms: TypeError Cannot read property declarations of undefined
Code
src-file1.tsx:
import React from "react";
type Tags = "span" | "div";
export const Hoc = <Tag extends Tags>(
TagElement: Tag,
): React.FunctionComponent => {
const Component = () => <TagElement />;
return Component;
};src-file2.tsx:
import React from "react";
type Tags = "span" | "div";
export const Hoc = (TagElement: Tags): React.FunctionComponent => {
const Component = () => <TagElement />;
return Component;
};Expected behavior:
Both npx tsc --strict --noEmit --jsx 'react' src-file1.tsx and npx tsc --strict --noEmit --jsx 'react' src-file2.tsx will run successfully.
Actual behavior:
npx tsc --strict --noEmit --jsx 'react' src-file2.tsx runs successfully, but npx tsc --strict --noEmit --jsx 'react' src-file1.tsx fails with the error message (where "$PWD" is the present working directory and "$HOME" is my home directory):
"$PWD"/node_modules/typescript/lib/tsc.js:87001
throw e;
^
TypeError: Cannot read property 'declarations' of undefined
at addImplementationSuccessElaboration ("$PWD"/node_modules/typescript/lib/tsc.js:57022:116)
at resolveCall ("$PWD"/node_modules/typescript/lib/tsc.js:56947:33)
at resolveJsxOpeningLikeElement ("$PWD"/node_modules/typescript/lib/tsc.js:57576:20)
at resolveSignature ("$PWD"/node_modules/typescript/lib/tsc.js:57597:28)
at getResolvedSignature ("$PWD"/node_modules/typescript/lib/tsc.js:57608:26)
at checkJsxOpeningLikeElementOrOpeningFragment ("$PWD"/node_modules/typescript/lib/tsc.js:55477:27)
at checkJsxSelfClosingElementDeferred ("$PWD"/node_modules/typescript/lib/tsc.js:55058:13)
at checkDeferredNode ("$PWD"/node_modules/typescript/lib/tsc.js:64402:21)
at Map.forEach (<anonymous>)
at checkDeferredNodes ("$PWD"/node_modules/typescript/lib/tsc.js:64373:37)
npm ERR! code 1
npm ERR! path "$PWD"
npm ERR! command failed
npm ERR! command sh -c tsc --strict --noEmit --jsx react --esModuleInterop src-file1.tsx
npm ERR! A complete log of this run can be found in:
npm ERR! "$HOME"/.npm/_logs/2020-11-20T20_34_21_223Z-debug.log
Playground Link:
Compiling the first source file crashes the web compiler,



while compiling the second source file succeeds.



bengry, capaj, remcohaszing, cztomsik, edtsech and 4 more
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue