microsoft / microsoft/TypeScript

class-factory mixins in type declaration files are impossible. (allow implicit return types in declaration files somehow)

Open
#35,715 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Search Terms

When the compiler is set to emit declaration files, class-factory mixins are no longer allowed. This is yet another issue that prevents class-factory mixins from being adopted in library code that need to be publish as JS with sibling declaration files.

Suggestion

Allow implicit return types to be somehow representable in declaration files.

Use Cases

Enables many use cases that are otherwise impossible when emitting declaration files. I believe declaration files should support all features of TS.

Examples

Write a mixin function, and try to emit declaration files.

Workaround

As a workaround I publish TypeScript source files in my NPM packages, then I point the types field in package.json to my source entry point. I don't publish declaration files because I can't build them.

Pointing to source files opens up other cans of worms, and prior to TS 3.6.3 I was not able to point to source files due to pre-existing bugs in tsc in that scenario. After TS 3.6.3, I can successfully publish source files and point types to sources containing class-factory mixins, but I'm afraid this is brittle and can break with an upgrade to TS (just as it was broken from some point prior to v3.6.3).

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

No source file or test is named. Start by reproducing the class-factory mixin example while emitting declaration files, then trace the declaration-emission behavior involved. Done means a supported representation of the mixin's implicit return type can be emitted without requiring the workaround of publishing TypeScript source files.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.