@tsonic/core 10.0.1 → 10.0.5
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.
- package/lang.d.ts +78 -0
- package/package.json +1 -1
package/lang.d.ts
CHANGED
|
@@ -169,6 +169,84 @@ export declare function nameof(expression: unknown): string;
|
|
|
169
169
|
*/
|
|
170
170
|
export declare function trycast<T>(value: unknown): T | null;
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Compile-time-only interface view.
|
|
174
|
+
*
|
|
175
|
+
* This is NOT a runtime cast. The compiler must erase this call before emitting C#.
|
|
176
|
+
*
|
|
177
|
+
* Primary use: treat a value as a CLR interface/nominal type for TypeScript type checking,
|
|
178
|
+
* without introducing runtime casts in emitted C# (important for EF Core precompilation).
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { asinterface } from "@tsonic/core/lang.js";
|
|
183
|
+
* import type { IQueryable } from "@tsonic/dotnet/System.Linq.js";
|
|
184
|
+
*
|
|
185
|
+
* const q = asinterface<IQueryable<User>>(db.Users);
|
|
186
|
+
* // q is typed as IQueryable<User> in TS, but emits without a cast in C#.
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export declare function asinterface<T>(value: unknown): T;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Parameter passing modifiers (call-site markers).
|
|
193
|
+
*
|
|
194
|
+
* These are compile-time-only intrinsics. The compiler must erase them and emit
|
|
195
|
+
* the corresponding C# argument modifiers: `out`, `ref`, `in`.
|
|
196
|
+
*
|
|
197
|
+
* These are *not* runtime functions.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { defaultof, out } from "@tsonic/core/lang.js";
|
|
202
|
+
*
|
|
203
|
+
* let value = defaultof<int>();
|
|
204
|
+
* if (dict.TryGetValue("key", out(value))) {
|
|
205
|
+
* // value is assigned by the call
|
|
206
|
+
* }
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export declare function out<T>(value: T): T;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Compile-time-only `ref` argument marker (emits `ref x`).
|
|
213
|
+
*/
|
|
214
|
+
export declare function ref<T>(value: T): T;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Compile-time-only `in` argument marker (emits `in x`).
|
|
218
|
+
*
|
|
219
|
+
* Named `inref` because `in` is a TypeScript reserved keyword.
|
|
220
|
+
*/
|
|
221
|
+
export declare function inref<T>(value: T): T;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Compile-time-only type selection marker.
|
|
225
|
+
*
|
|
226
|
+
* This is NOT a runtime type test. The compiler must erase this call before emitting C#.
|
|
227
|
+
*
|
|
228
|
+
* Primary use: specialize a single TypeScript overload implementation into one CLR method
|
|
229
|
+
* per signature (e.g., overriding a protected virtual overload family).
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* import { istype } from "@tsonic/core/lang.js";
|
|
234
|
+
* import type { int } from "@tsonic/core/types.js";
|
|
235
|
+
*
|
|
236
|
+
* // Overload signatures
|
|
237
|
+
* Foo(x: int): int;
|
|
238
|
+
* Foo(x: string): int;
|
|
239
|
+
*
|
|
240
|
+
* // Single implementation (compile-time specialized)
|
|
241
|
+
* Foo(p0: unknown): unknown {
|
|
242
|
+
* if (istype<int>(p0)) return p0 + 1;
|
|
243
|
+
* if (istype<string>(p0)) return p0.length;
|
|
244
|
+
* throw new Error("unreachable");
|
|
245
|
+
* }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export declare function istype<T>(value: unknown): value is T;
|
|
249
|
+
|
|
172
250
|
// ============================================================================
|
|
173
251
|
// Extension Method Intrinsics
|
|
174
252
|
// ============================================================================
|