elsa-workflows / elsa-workflows/elsa-core

Enhance Elsa 2 JavaScript IntelliSense: Add Constructor + Enums Support to TypeScript Definitions

Open
#7,540 1 comment 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

## Enhancement Request

### Enhancement Overview
**Is your enhancement request related to a problem? Please describe.**
Currently, Elsa 2’s JavaScript IntelliSense does not display constructors for .NET classes in the generated TypeScript definitions. This makes it unclear to users which constructor overloads are available when using .NET types in JavaScript expressions, leading to confusion and reduced productivity when working with types that require specific constructor parameters.
The EnumTypeDefintionProvider + DotNetTypeScriptDefinitionProvider combination is not rendering enums as enums.

### Proposed Enhancement
**Describe the enhancement you'd like**
- Enhance Elsa 2’s TypeScript definition generation to include constructor signatures for .NET classes in the generated TypeScript output.
- Update the `DotNetTypeScriptDefinitionProvider` to enumerate public constructors for each class and render corresponding TypeScript `constructor(...)` signatures.
- This will provide full IntelliSense support for class instantiation, showing available parameters and overloads directly in the editor.
- Handle enums correctly so that they render them as enums. They currently render as number i.e. `"DayOfWeek: number;"`

### Alternative Solutions
**Describe alternatives you've considered**
- Relying on documentation or external references for constructor signatures, which is inefficient and error-prone.
- Manually adding constructor signatures to the generated TypeScript, which is not maintainable and does not scale.
- Using only interfaces, which does not support instantiation or method IntelliSense.

None of these alternatives provide a seamless, maintainable, and discoverable experience for users.

### Use Cases
**Identify potential use cases**
- Workflow authors using Elsa’s JavaScript expressions to instantiate .NET types and needing to know the required constructor parameters.
- Developers integrating custom .NET types into Elsa workflows and wanting to expose clear usage patterns to script authors.
- Any scenario where .NET classes are used in JavaScript and require explicit construction.
- Any scenario where you want to use enums in JavaScript with names + numeric values being clearly visible

### Impact of Enhancement
**Explain the potential impact**
- Improves developer productivity by providing accurate IntelliSense for constructors.
- Reduces errors and guesswork when instantiating .NET types in JavaScript.
- Enhances the onboarding experience for new users by making available constructors discoverable directly in the editor.
- Aligns Elsa’s TypeScript definitions with standard TypeScript/JavaScript development practices.

### Visuals and Mockups
**Provide any visuals**
_No visuals attached, but the enhancement would result in TypeScript definitions like:_
```
declare class MyClass {
constructor(param1: string, param2: number);
// ...
}
```
```
declare enum DayOfWeek {
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
}
declare enum DateTimeKind {
Unspecified = 0,
Utc = 1,
Local = 2,
}
```
This would enable IntelliSense to show constructor signatures and Enum values in Monaco.

### Additional Context
**Add any other context**
- This enhancement aligns Elsa’s JavaScript integration with user expectations from modern TypeScript tooling.
- Similar features are present in other .NET-to-TypeScript generators, and this would bring Elsa in line with those tools.
- The change is backward-compatible and only affects the TypeScript definition output, not runtime behaviour.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.