microsoft / microsoft/TypeScript

Declarations are not generated for a high order component

Open
#28,040 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Declaration Emit Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.2.0-dev.201xxxxx, 2.9.1, 3.1.3

Search Terms:

declaration, high-order, hoc

Code

export function Executor(func: () => any) {
  class ExecutingClass {
    execute() {
      func();
    }
  }

  return ExecutingClass;
}

Expected behavior:

Running both tsc and tsc -d produces no errors.

Actual behavior:

When I'm running tsc on this code, everything works fine.
When I'm running tsc -d on this code, I have this error:

hoc.ts:1:17 - error TS4060: Return type of exported function has or is using private name 'ExecutingClass'.

1 export function Executor(func: () => any) {

It is still possible to generate typings for this if you change code to this:

export function Executor(func: () => any) {
  const ExecutingClass = class {
    execute() {
      func();
    }
  }

  return ExecutingClass;
}

export default Executor;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with the listed TypeScript versions using both tsc and tsc -d, then compare the behavior with the anonymous-class variant. The issue is resolved when the original exported high-order component generates declarations without TS4060; no repository file or test is named.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.