Skip to content

Feat: Elsa2 Enhance TypeScript generation and type utilities#7696

Open
terry-delph wants to merge 1 commit into
elsa-workflows:2.xfrom
mintra-as:feature/elsa2-intellisense-constructor-enum
Open

Feat: Elsa2 Enhance TypeScript generation and type utilities#7696
terry-delph wants to merge 1 commit into
elsa-workflows:2.xfrom
mintra-as:feature/elsa2-intellisense-constructor-enum

Conversation

@terry-delph

@terry-delph terry-delph commented Jun 5, 2026

Copy link
Copy Markdown
Contributor
  • Added IsNullableType extension method for nullable type checks.
  • Made Priority property in DefaultActivityTypeDefinitionRenderer virtual to allow correct priorty to be used when subclassing
  • Replaced a usage of AutoMapper.Internal with Elsa.Scripting.JavaScript.Extensions. IsNullableType method.
  • Improved RenderTypeDeclaration to handle enums and class constructors.
  • Updated EnumTypeDefinitionProvider to refine enum handling and definitions.

Purpose

This PR enhances Elsa 2's TypeScript definition generation to include .NET class constructor signatures and correctly render enums instead of treating them as plain numbers. These changes provide full IntelliSense support and autocomplete functionality for workflow authors using JavaScript expressions.


Scope

Select one primary concern:

  • Bug fix (behavior change)
  • Refactor (no behavior change)
  • Documentation update
  • Formatting / code cleanup
  • Dependency / build update
  • New feature

Description

Problem

Currently, DotNetTypeScriptDefinitionProvider does not display constructors for .NET classes, making it unclear which overloads are available during JavaScript type instantiation. Additionally, the EnumDefinitionProvider renders enums as generic numbers (e.g., DayOfWeek: number;), hiding the actual enum names and values from the editor.

Solution

  • Updated RenderTypeDeclaration and DotNetTypeScriptDefinitionProvider to enumerate public constructors and generate corresponding TypeScript constructor(...) signatures.
  • Refined EnumTypeDefinitionProvider to generate proper TypeScript enum structures rather than plain numeric properties.
  • Made the Priority property in DefaultActivityTypeDefinitionRenderer virtual to allow proper prioritization when subclassing.
  • Replaced a AutoMapper.Internal dependency with a new IsNullableType extension method in Elsa.Scripting.JavaScript.Extensions.

Verification

Steps:

  1. Open a workflow containing JavaScript expressions using the Monaco editor.
  2. Attempt to instantiate a registered .NET class (e.g., new MyClass(...)) and trigger IntelliSense.
  3. Reference a registered .NET enum (e.g., DayOfWeek) within a JavaScript expression and trigger IntelliSense.

Expected outcome:

  1. The editor displays available constructor overloads and parameter types.
  2. Enums are fully autocompleteable with their specific name-value pairs instead of displaying as a standard number.
  3. All existing automated tests continue to pass.

Screenshots / Recordings (if applicable)

Target TypeScript Definition Output Example:

declare class MyClass {
  constructor(param1: string);
  constructor(param1: string, param2: number);
  constructor(param1: string, param2: number, param2: DayOfWeek);
}

declare enum DayOfWeek {
  Sunday = 0,
  Monday = 1,
  // ...
}

Checklist

  • The PR is focused on a single concern
  • Commit messages follow the recommended convention
  • Tests added or updated (if applicable)
  • Documentation updated (if applicable)
  • No unrelated cleanup included
  • All tests pass

…#7540

- Added `IsNullableType` extension method for nullable type checks.
- Made `Priority` property in `DefaultActivityTypeDefinitionRenderer` virtual to allow correct priorty to be used when subclassing
- Replaced a usage of `AutoMapper.Internal` with `Elsa.Scripting.JavaScript.Extensions`.  IsNullableType method.
- Improved `RenderTypeDeclaration` to handle enums and class constructors.
- Updated `EnumTypeDefinitionProvider` to refine enum handling and definitions.
@terry-delph terry-delph marked this pull request as ready for review June 5, 2026 09:08
@greptile-apps

greptile-apps Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@terry-delph

Copy link
Copy Markdown
Contributor Author

@sfmskywalker
Is there something I can do to assist you in reviewing this PR?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant