You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implement const type parameters support with TypeScript 5.0+ compatibility
- Added const modifier detection for type parameters in transformer
- Enhanced IRTemplateParameter interface with isConst flag
- Updated code generator to include /* const */ comments for const type parameters
- Added comprehensive test suite for const type parameter scenarios
- Updated documentation with examples and implementation details
Technical changes:
- Fixed duplicate IRTemplateParameter interface definitions
- Added hasConstModifier method for robust const detection
- Enhanced template parameter generation in both functions and classes
- Added feature detection in AST parser for const type parameters
This implementation follows the prototype pattern while providing
a cleaner solution with proper type safety and documentation.
Tests cover:
- Basic const type parameters on functions
- Multiple const type parameters
- Mixed const and non-const parameters
- Const type parameters on class methods
- Generic classes with const type parameters
- Constrained const type parameters
Copy file name to clipboardExpand all lines: RELEASE_NOTES_v0.8.x.md
+95-4Lines changed: 95 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -624,19 +624,19 @@ class ConfigManager {
624
624
// Definite assignment assertion - property will be assigned in initialize()
625
625
apiUrl!: string;
626
626
timeout!: number;
627
-
debug?: boolean; // Optional property for comparison
628
-
627
+
debug?: boolean; // Optional property for comparison
628
+
629
629
// Additional properties with assertions
630
630
initialized!: boolean;
631
631
settings!: { [key: string]: any };
632
-
632
+
633
633
initialize(url: string, timeoutMs: number) {
634
634
this.apiUrl = url;
635
635
this.timeout = timeoutMs;
636
636
this.initialized = true;
637
637
this.settings = { theme: "dark" };
638
638
}
639
-
639
+
640
640
isReady(): boolean {
641
641
return this.initialized;
642
642
}
@@ -673,6 +673,94 @@ auto ConfigManager::initialize(js::string url, js::number timeoutMs) {
673
673
674
674
**Note:** The definite assignment assertion (`!`) is a TypeScript compile-time feature that suppresses strict property initialization checking. In C++, this translates to declaring properties without initializers, which is the natural behavior. TypeScript2Cxx handles this automatically - properties with definite assignment assertions are transpiled as regular C++ member variables that are assigned later in constructors or initialization methods.
675
675
676
+
#### Const Type Parameters Support
677
+
678
+
TypeScript 5.0+ introduces const type parameters using the `const` modifier on generic type parameters. This feature enables better type inference and literal type preservation in generic functions and classes.
**Note:** Const type parameters are a TypeScript compile-time feature for improved type inference and literal type preservation. In C++, TypeScript2Cxx generates standard template parameters but adds `/* const */` comments to indicate which parameters had the const modifier in the original TypeScript code. This helps maintain readability and provides context for developers familiar with the TypeScript source.
763
+
676
764
### 🔧 Implementation Details
677
765
678
766
- **Type System**:
@@ -694,8 +782,11 @@ auto ConfigManager::initialize(js::string url, js::number timeoutMs) {
694
782
- **Transform Layer**:
695
783
- Enhanced type assertion (`as`) expression handling to properly pass through expressions
696
784
- Type aliases now correctly skip runtime code generation (they're compile-time only)
785
+
- Added `hasConstModifier` method for detecting const modifiers on type parameters
786
+
- Enhanced `IRTemplateParameter` interface with `isConst` flag for const type parameter tracking
697
787
- **Code Generation**:
698
788
- Fixed Object identifier mapping (was incorrectly dual-mapped to both js::Object and js::object)
789
+
- Enhanced template parameter generation to include `/* const */` comments for const type parameters
699
790
- **Runtime Library**:
700
791
- Added `js::Object` namespace with static utility methods
0 commit comments