Typescript: `partial class` rationale

Created on 18 Jun 2019  Â·  3Comments  Â·  Source: microsoft/TypeScript

Search Terms

Suggestion

  • TS already have namespace. Why it cannot have partial class only valid in namespace and in same module (like internal)?
  • Partial classes may be distinct from C# implementation.
    One partial class may require declaration/implementation from another, otherwise compilation should fail.

Use Cases

  • Code generation tools: ATM there is no way to extend TypeScript compiler with custom resolvers, build hooks or anything.
  • Without this feature most of preconditions cannot be checked at build time and everything must be checked at boot or even worse at runtime.

Examples

  • There are nice examples in the wild, VS and C# can be one well known.
  • My specific use case will be to rendering GraphQL schema into partial classes, you will only implement resolvers. All checked :heavy_check_mark:
    (Yes. Current approaches are really bad on server.)

Checklist

My suggestion meets these guidelines:

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

All 3 comments

You found #563 already, which has plenty of information

Ok. I'm reading this as Typescript will never have partial classes

That's correct

Was this page helpful?
0 / 5 - 0 ratings