@tsonic/core 10.0.22 → 10.0.26

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/lang.d.ts +71 -5
  2. package/package.json +2 -2
package/lang.d.ts CHANGED
@@ -395,6 +395,51 @@ export type Ctor<T = unknown, Args extends readonly any[] = readonly any[]> = ne
395
395
  /** Any attribute class constructor. */
396
396
  export type AttributeCtor = Ctor<object, readonly any[]>;
397
397
 
398
+ /**
399
+ * C# attribute target specifiers (the `target:` prefix in `[target: Attr]`).
400
+ *
401
+ * @example
402
+ * ```ts
403
+ * import { attributes as A, AttributeTargets } from "@tsonic/core/lang.js";
404
+ *
405
+ * class Native {
406
+ * foo(): boolean { return true; }
407
+ * }
408
+ *
409
+ * A.on(Native)
410
+ * .method(x => x.foo)
411
+ * .target(AttributeTargets.return)
412
+ * .add(MarshalAsAttribute, UnmanagedType.Bool);
413
+ * ```
414
+ *
415
+ * Emits C#:
416
+ * ```csharp
417
+ * [return: MarshalAs(UnmanagedType.Bool)]
418
+ * public bool foo() { ... }
419
+ * ```
420
+ */
421
+ export interface AttributeTargets {
422
+ readonly assembly: "assembly";
423
+ readonly module: "module";
424
+ readonly type: "type";
425
+ readonly method: "method";
426
+ readonly property: "property";
427
+ readonly field: "field";
428
+ readonly event: "event";
429
+ readonly param: "param";
430
+ readonly return: "return";
431
+ }
432
+
433
+ /**
434
+ * Value-level constants for `AttributeTarget`.
435
+ *
436
+ * Note: This module is compile-time only; Tsonic erases these references.
437
+ */
438
+ export declare const AttributeTargets: AttributeTargets;
439
+
440
+ /** Union of valid attribute target strings. */
441
+ export type AttributeTarget = AttributeTargets[keyof AttributeTargets];
442
+
398
443
  /**
399
444
  * Extract constructor parameters across multiple overloads.
400
445
  *
@@ -468,10 +513,10 @@ export type SelectedMethodValue<T> = (...args: any[]) => any;
468
513
  */
469
514
  export interface OnBuilder<T> {
470
515
  /** Attach attributes to the type declaration (C# class/interface). */
471
- type: AttributeTargetBuilder;
516
+ type: AttributeTargetBuilder<"type">;
472
517
 
473
518
  /** Attach attributes to the constructor. */
474
- ctor: AttributeTargetBuilder;
519
+ ctor: AttributeTargetBuilder<"method">;
475
520
 
476
521
  /**
477
522
  * Select a method to annotate.
@@ -484,7 +529,7 @@ export interface OnBuilder<T> {
484
529
  */
485
530
  method<K extends MethodKeys<T>>(
486
531
  selector: (t: T) => T[K]
487
- ): AttributeTargetBuilder;
532
+ ): AttributeTargetBuilder<"method" | "return">;
488
533
 
489
534
  /**
490
535
  * Select a property to annotate.
@@ -494,7 +539,7 @@ export interface OnBuilder<T> {
494
539
  */
495
540
  prop<K extends PropertyKeys<T>>(
496
541
  selector: (t: T) => T[K]
497
- ): AttributeTargetBuilder;
542
+ ): AttributeTargetBuilder<"property" | "field">;
498
543
  }
499
544
 
500
545
  /**
@@ -503,7 +548,28 @@ export interface OnBuilder<T> {
503
548
  * - add(AttrCtor, ...args)
504
549
  * - add(A.attr(AttrCtor, ...args))
505
550
  */
506
- export interface AttributeTargetBuilder {
551
+ export interface AttributeTargetBuilder<
552
+ TAllowedTargets extends AttributeTarget = AttributeTarget,
553
+ > {
554
+ /**
555
+ * Add a C# attribute target specifier.
556
+ *
557
+ * @example
558
+ * ```ts
559
+ * A.on(User)
560
+ * .prop(x => x.name)
561
+ * .target(AttributeTargets.field)
562
+ * .add(NonSerializedAttribute);
563
+ * ```
564
+ *
565
+ * Emits C#:
566
+ * ```csharp
567
+ * [field: NonSerialized]
568
+ * public string name { get; set; }
569
+ * ```
570
+ */
571
+ target(target: TAllowedTargets): AttributeTargetBuilder<TAllowedTargets>;
572
+
507
573
  /**
508
574
  * Add an attribute by constructor + arguments.
509
575
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsonic/core",
3
- "version": "10.0.22",
3
+ "version": "10.0.26",
4
4
  "description": "Core type definitions for Tsonic (versioned by .NET major)",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -25,6 +25,6 @@
25
25
  },
26
26
  "homepage": "https://github.com/tsoniclang/core#readme",
27
27
  "peerDependencies": {
28
- "@tsonic/dotnet": "10.0.21"
28
+ "@tsonic/dotnet": "10.0.26"
29
29
  }
30
30
  }