Skip to content

partial class rationale #31965

@langpavel

Description

@langpavel

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 ✔️
    (Yes. Current approaches are really bad on server.)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions