@tsonic/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +41 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsonic/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Core type definitions for Tsonic - TypeScript to native compiler",
5
5
  "type": "module",
6
6
  "keywords": [
package/types.d.ts CHANGED
@@ -55,3 +55,44 @@ export type ptr<T> = unknown;
55
55
  // NOTE: ref<T>, out<T>, In<T> have been removed.
56
56
  // Parameter modifiers will be expressed via syntax, not types.
57
57
  // See spec for forthcoming ref/out/in parameter syntax.
58
+
59
+ // ============================================================================
60
+ // Value Type Markers
61
+ // ============================================================================
62
+
63
+ /**
64
+ * Marker interface for C# struct types.
65
+ *
66
+ * Types that extend `struct` will be emitted as C# structs instead of classes.
67
+ * This enables value semantics and stack allocation in the generated code.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { struct } from "@tsonic/core/types.js";
72
+ *
73
+ * // This becomes a C# struct
74
+ * export interface Point extends struct {
75
+ * x: number;
76
+ * y: number;
77
+ * }
78
+ *
79
+ * // Use as generic constraint for nullable value types
80
+ * function wrap<T extends struct>(value: T | null): T | null {
81
+ * return value;
82
+ * }
83
+ * ```
84
+ *
85
+ * In C#, this emits:
86
+ * ```csharp
87
+ * public struct Point {
88
+ * public double x { get; set; }
89
+ * public double y { get; set; }
90
+ * }
91
+ *
92
+ * // With constraint: where T : struct
93
+ * T? Wrap<T>(T? value) where T : struct => value;
94
+ * ```
95
+ */
96
+ export interface struct {
97
+ readonly __brand: unique symbol;
98
+ }