1 | # typescript-json-schema test examples
|
2 |
|
3 | ## [abstract-class](./test/programs/abstract-class)
|
4 |
|
5 | ```ts
|
6 | export abstract class AbstractBase {
|
7 | propA:number;
|
8 | propB:string;
|
9 |
|
10 | abstract doNotInclude(): void;
|
11 | }
|
12 |
|
13 | ```
|
14 |
|
15 |
|
16 | ## [abstract-extends](./test/programs/abstract-extends)
|
17 |
|
18 | ```ts
|
19 | import { AbstractBase } from "../abstract-class/main";
|
20 |
|
21 | class MyObjectFromAbstract extends AbstractBase {
|
22 | doNotInclude(): void { }
|
23 |
|
24 | propB:string;
|
25 | propC:number;
|
26 | }
|
27 | ```
|
28 |
|
29 |
|
30 | ## [annotation-default](./test/programs/annotation-default)
|
31 |
|
32 | ```ts
|
33 | interface MyObject {
|
34 | /**
|
35 | * @default true
|
36 | */
|
37 | varBoolean: boolean;
|
38 | /**
|
39 | * @default 123
|
40 | */
|
41 | varInteger: number;
|
42 | /**
|
43 | * @default 3.21
|
44 | */
|
45 | varFloat: number;
|
46 | /**
|
47 | * @default "foo"
|
48 | */
|
49 | varString: string;
|
50 | /**
|
51 | * @default [true, false, true]
|
52 | */
|
53 | varBooleanArray: boolean[];
|
54 | /**
|
55 | * @default [1, 2, 3, 4, 5]
|
56 | */
|
57 | varIntegerArray: number[];
|
58 | /**
|
59 | * @default [1.23, 65.21, -123.40, 0, 1000000.0001]
|
60 | */
|
61 | varFloatArray: number[];
|
62 | /**
|
63 | * @default ["a", "b", "c", "..."]
|
64 | */
|
65 | varStringArray: string[];
|
66 | /**
|
67 | * @default [true, 123, 3.21, "foo"]
|
68 | */
|
69 | varMixedArray: any[];
|
70 | }
|
71 | ```
|
72 |
|
73 |
|
74 | ## [annotation-id](./test/programs/annotation-id)
|
75 |
|
76 | ```ts
|
77 | /**
|
78 | * @id filled#
|
79 | */
|
80 | interface MySubObject {
|
81 | a: boolean;
|
82 | }
|
83 |
|
84 | interface MyObject {
|
85 | /**
|
86 | * @id empty#
|
87 | */
|
88 | empty;
|
89 |
|
90 | filled: MySubObject;
|
91 | }
|
92 | ```
|
93 |
|
94 |
|
95 | ## [annotation-items](./test/programs/annotation-items)
|
96 |
|
97 | ```ts
|
98 | interface MyObject {
|
99 | /**
|
100 | * @items {"type":"integer"}
|
101 | */
|
102 | a: number[];
|
103 |
|
104 | /**
|
105 | * @items {"type":"integer", "minimum":0}
|
106 | */
|
107 | b: number[];
|
108 |
|
109 | /**
|
110 | * @items.type integer
|
111 | * @items.minimum 0
|
112 | */
|
113 | c: number[];
|
114 |
|
115 | /**
|
116 | * @items.type integer
|
117 | */
|
118 | d: number[];
|
119 |
|
120 | /**
|
121 | * @items {"type":"string", "format":"email"}
|
122 | */
|
123 | emails: string[];
|
124 |
|
125 | /**
|
126 | * @items.type string
|
127 | * @items.format email
|
128 | */
|
129 | emails2: string[];
|
130 |
|
131 | }
|
132 | ```
|
133 |
|
134 |
|
135 | ## [annotation-ref](./test/programs/annotation-ref)
|
136 |
|
137 | ```ts
|
138 | interface MySubObject {}
|
139 |
|
140 | interface MyObject {
|
141 | /**
|
142 | * @$ref http://my-schema.org
|
143 | */
|
144 | externalRef;
|
145 |
|
146 | /**
|
147 | * @$ref http://my-schema.org
|
148 | */
|
149 | externalRefOverride: MySubObject;
|
150 | }```
|
151 |
|
152 |
|
153 | ## [annotation-tjs](./test/programs/annotation-tjs)
|
154 |
|
155 | ```ts
|
156 | // All of these formats are defined in this specification: http://json-schema.org/latest/json-schema-validation.html#rfc.section.8.3
|
157 | interface MyObject {
|
158 | /**
|
159 | * @TJS-format date-time
|
160 | */
|
161 | dateTime: string;
|
162 |
|
163 | /**
|
164 | * @TJS-format email
|
165 | */
|
166 | email: string;
|
167 |
|
168 | /**
|
169 | * @TJS-format hostname
|
170 | */
|
171 | hostname: string;
|
172 |
|
173 | /**
|
174 | * @TJS-format ipv4
|
175 | */
|
176 | ipv4: string;
|
177 |
|
178 | /**
|
179 | * @TJS-format ipv6
|
180 | */
|
181 | ipv6: string;
|
182 |
|
183 | /**
|
184 | * @TJS-format uri
|
185 | */
|
186 | uri: string;
|
187 |
|
188 | /**
|
189 | * @TJS-format uri-reference
|
190 | */
|
191 | uriReference: string;
|
192 |
|
193 | /**
|
194 | * @TJS-format uri-template
|
195 | */
|
196 | uriTemplate: string;
|
197 |
|
198 | /**
|
199 | * @TJS-format json-pointer
|
200 | */
|
201 | jsonPointer: string;
|
202 |
|
203 | /**
|
204 | * @TJS-pattern ^[a-zA-Z0-9]{4}-abc_123$
|
205 | */
|
206 | regexPattern: string;
|
207 |
|
208 | /**
|
209 | * @TJS-pattern ^[a-zA-Z0-9]{4}-abc_123$
|
210 | */
|
211 | regexPatternWithWhitespace: string;
|
212 |
|
213 | /**
|
214 | * @TJS-minimum 5
|
215 | */
|
216 | oneCharacter: number;
|
217 |
|
218 | /**
|
219 | * @TJS-examples ["foo", 1]
|
220 | */
|
221 | examples: string;
|
222 |
|
223 | /**
|
224 | * @TJS-hide
|
225 | */
|
226 | booleanAnnotationDefaultValue: string;
|
227 |
|
228 | /**
|
229 | * @TJS-hide true
|
230 | */
|
231 | booleanAnnotationWithTrue: string;
|
232 |
|
233 | /**
|
234 | * @TJS-hide false
|
235 | */
|
236 | booleanAnnotationWithFalse: string;
|
237 | }
|
238 | ```
|
239 |
|
240 |
|
241 | ## [any-unknown](./test/programs/any-unknown)
|
242 |
|
243 | ```ts
|
244 | export interface MyObject {
|
245 | a: any;
|
246 | b: unknown;
|
247 | }```
|
248 |
|
249 |
|
250 | ## [argument-id](./test/programs/argument-id)
|
251 |
|
252 | ```ts
|
253 | interface MyObject {
|
254 | someProp: string;
|
255 | referenceType: ReferenceType;
|
256 | }
|
257 |
|
258 | interface ReferenceType {
|
259 | reference: true;
|
260 | }
|
261 | ```
|
262 |
|
263 |
|
264 | ## [array-and-description](./test/programs/array-and-description)
|
265 |
|
266 | ```ts
|
267 | export interface MyObject {
|
268 | /**
|
269 | * A name
|
270 | */
|
271 | name?: string;
|
272 | description?: string;
|
273 | test: any[];
|
274 | }
|
275 | ```
|
276 |
|
277 |
|
278 | ## [array-readonly](./test/programs/array-readonly)
|
279 |
|
280 | ```ts
|
281 | export type MyReadOnlyArray = ReadonlyArray<number>;
|
282 | ```
|
283 |
|
284 |
|
285 | ## [array-types](./test/programs/array-types)
|
286 |
|
287 | ```ts
|
288 | type MyArray = Array<string | number>;
|
289 | ```
|
290 |
|
291 |
|
292 | ## [builtin-names](./test/programs/builtin-names)
|
293 |
|
294 | ```ts
|
295 | declare namespace Ext {
|
296 | export class Array {
|
297 | }
|
298 |
|
299 | export class Foo {
|
300 | bar: Ext.Array;
|
301 | }
|
302 | }
|
303 | ```
|
304 |
|
305 |
|
306 | ## [class-extends](./test/programs/class-extends)
|
307 |
|
308 | ```ts
|
309 | class Base {
|
310 | propA:number;
|
311 | }
|
312 |
|
313 | class MyObject extends Base {
|
314 | propB:number;
|
315 | }
|
316 | ```
|
317 |
|
318 |
|
319 | ## [class-single](./test/programs/class-single)
|
320 |
|
321 | ```ts
|
322 | class MyObject {
|
323 | constructor() {}
|
324 | propA:number;
|
325 | propB:number;
|
326 | doNotInclude(): void {}
|
327 | }
|
328 | ```
|
329 |
|
330 |
|
331 | ## [comments](./test/programs/comments)
|
332 |
|
333 | ```ts
|
334 |
|
335 | /**
|
336 | * Description of Vector3D, a type alias to a array of integers with length 3
|
337 | * If run without useTypeAliasRef, this comment should be ignored but
|
338 | * the other annotations should be inherited
|
339 | * @minItems 3
|
340 | * @maxItems 3
|
341 | */
|
342 | type Vector3D = number[];
|
343 |
|
344 | /**
|
345 | * Description of MyObject, a top level object,
|
346 | * which also has a comment that spans
|
347 | * multiple lines
|
348 | *
|
349 | * @additionalProperties false
|
350 | * @unsupportedAnnotationThatShouldBeIgnored
|
351 | */
|
352 | interface MyObject {
|
353 |
|
354 | /**
|
355 | * Description of opacity, a field with min/max values
|
356 | * @minimum 0
|
357 | * @maximum 100
|
358 | */
|
359 | opacity: number;
|
360 |
|
361 | /**
|
362 | * Description of field position, of aliased type Vector3D, which should inherit its annotations
|
363 | */
|
364 | position: Vector3D;
|
365 |
|
366 | /**
|
367 | * Description of rotation, a field with an anonymous type
|
368 | */
|
369 | rotation: {
|
370 | /**
|
371 | * Description of the value yaw inside an anonymous type, with min/max annotations
|
372 | * @minimum -90
|
373 | * @maximum 90
|
374 | */
|
375 | yaw: number;
|
376 | };
|
377 | }
|
378 | ```
|
379 |
|
380 |
|
381 | ## [comments-imports](./test/programs/comments-imports)
|
382 |
|
383 | ```ts
|
384 | /**
|
385 | * Description of Color.
|
386 | *
|
387 | * @pattern ^[0-9a-f]{6}$
|
388 | */
|
389 | export type Color = string;
|
390 | ```
|
391 |
|
392 |
|
393 | ## [comments-imports](./test/programs/comments-imports)
|
394 |
|
395 | ```ts
|
396 | import { Color } from "./color";
|
397 | import { Text } from "./text";
|
398 |
|
399 | /** Description of MyObject */
|
400 | export interface MyObject {
|
401 | /** Description of MyObject color property. */
|
402 | color: Color;
|
403 |
|
404 | /** Description of MyObject text property. */
|
405 | text: Text;
|
406 | }
|
407 | ```
|
408 |
|
409 |
|
410 | ## [comments-imports](./test/programs/comments-imports)
|
411 |
|
412 | ```ts
|
413 | import { Color } from "./color";
|
414 |
|
415 | /**
|
416 | * Description of Text interface.
|
417 | */
|
418 | export interface Text {
|
419 | /** Description of text property. */
|
420 | text: string;
|
421 |
|
422 | /** Description of text color property. */
|
423 | color: Color;
|
424 | }
|
425 | ```
|
426 |
|
427 |
|
428 | ## [comments-override](./test/programs/comments-override)
|
429 |
|
430 | ```ts
|
431 |
|
432 | /**
|
433 | * Type-level description
|
434 | * @additionalProperties true
|
435 | */
|
436 | export interface MySubObject {
|
437 | value: string;
|
438 | }
|
439 |
|
440 | export interface MyObject {
|
441 | list: MySubObject[];
|
442 |
|
443 | sub1: MySubObject;
|
444 |
|
445 | /**
|
446 | * Property-level description
|
447 | * @additionalProperties false
|
448 | */
|
449 | sub2: MySubObject;
|
450 |
|
451 | /**
|
452 | * Date property description
|
453 | */
|
454 | date: Date;
|
455 | }
|
456 | ```
|
457 |
|
458 |
|
459 | ## [custom-dates](./test/programs/custom-dates)
|
460 |
|
461 | ```ts
|
462 | namespace foo {
|
463 | export interface Date {
|
464 | day?: number;
|
465 | month?: number;
|
466 | year?: number;
|
467 | }
|
468 |
|
469 | export interface Bar {
|
470 | date: Date;
|
471 | }
|
472 | }
|
473 | ```
|
474 |
|
475 |
|
476 | ## [dates](./test/programs/dates)
|
477 |
|
478 | ```ts
|
479 | type DateAlias = Date;
|
480 |
|
481 | interface MyObject {
|
482 | var1: Date;
|
483 | var2: DateAlias;
|
484 | }
|
485 | ```
|
486 |
|
487 |
|
488 | ## [default-properties](./test/programs/default-properties)
|
489 |
|
490 | ```ts
|
491 | type Foo = "a" | "b" | "c" | boolean | number;
|
492 |
|
493 | class MyObject {
|
494 | varBoolean: Foo = <any> false;
|
495 | varInteger: Foo = <any> 123;
|
496 | varString: Foo = <any> "123";
|
497 | }
|
498 | ```
|
499 |
|
500 |
|
501 | ## [enums-compiled-compute](./test/programs/enums-compiled-compute)
|
502 |
|
503 | ```ts
|
504 | enum Enum {
|
505 | X = 1 << 1,
|
506 | Y = 1 << 2,
|
507 | Z = X | Y,
|
508 | A = 1,
|
509 | }
|
510 | ```
|
511 |
|
512 |
|
513 | ## [enums-mixed](./test/programs/enums-mixed)
|
514 |
|
515 | ```ts
|
516 | enum Enum {
|
517 | A, // = 0
|
518 | B = 1,
|
519 | C = true as any,
|
520 | D = "str" as any,
|
521 | E = null
|
522 | }
|
523 |
|
524 | interface MyObject {
|
525 | foo: Enum;
|
526 | }
|
527 | ```
|
528 |
|
529 |
|
530 | ## [enums-number](./test/programs/enums-number)
|
531 |
|
532 | ```ts
|
533 | enum Enum {
|
534 | X = 1,
|
535 | Y = 2
|
536 | }
|
537 |
|
538 | interface MyObject {
|
539 | foo: Enum;
|
540 | }
|
541 | ```
|
542 |
|
543 |
|
544 | ## [enums-number-initialized](./test/programs/enums-number-initialized)
|
545 |
|
546 | ```ts
|
547 | enum Enum {
|
548 | X = 10,
|
549 | Y,
|
550 | Z,
|
551 | A = 1,
|
552 | }
|
553 | ```
|
554 |
|
555 |
|
556 | ## [enums-string](./test/programs/enums-string)
|
557 |
|
558 | ```ts
|
559 | enum Enum {
|
560 | X = "x" as any,
|
561 | Y = "y" as any,
|
562 | Z = "123" as any
|
563 | }
|
564 |
|
565 | interface MyObject {
|
566 | foo: Enum;
|
567 | }
|
568 | ```
|
569 |
|
570 |
|
571 | ## [enums-value-in-interface](./test/programs/enums-value-in-interface)
|
572 |
|
573 | ```ts
|
574 | export enum A {
|
575 | B,
|
576 | C,
|
577 | D,
|
578 | };
|
579 |
|
580 | export interface MyObject {
|
581 | code: A.B;
|
582 | };
|
583 | ```
|
584 |
|
585 |
|
586 | ## [extra-properties](./test/programs/extra-properties)
|
587 |
|
588 | ```ts
|
589 | export interface MyObject {
|
590 | required: string;
|
591 | optional?: number;
|
592 | [name: string]: string|number;
|
593 | }
|
594 | ```
|
595 |
|
596 |
|
597 | ## [force-type](./test/programs/force-type)
|
598 |
|
599 | ```ts
|
600 | /** @TJS-type number */
|
601 | export class Widget {}
|
602 |
|
603 | export interface MyObject {
|
604 | name: string;
|
605 |
|
606 | mainWidget: Widget;
|
607 | otherWidgets: Widget[];
|
608 | }
|
609 | ```
|
610 |
|
611 |
|
612 | ## [force-type-imported](./test/programs/force-type-imported)
|
613 |
|
614 | ```ts
|
615 | import { Widget } from "./widget";
|
616 |
|
617 | export interface MyObject {
|
618 | name: string;
|
619 |
|
620 | mainWidget: Widget;
|
621 | otherWidgets: Widget[];
|
622 | }
|
623 | ```
|
624 |
|
625 |
|
626 | ## [force-type-imported](./test/programs/force-type-imported)
|
627 |
|
628 | ```ts
|
629 | /** @TJS-type number */
|
630 | export class Widget {}
|
631 | ```
|
632 |
|
633 |
|
634 | ## [generate-all-types](./test/programs/generate-all-types)
|
635 |
|
636 | ```ts
|
637 |
|
638 |
|
639 | interface MyInterface {
|
640 |
|
641 | }
|
642 |
|
643 | class MyObject {
|
644 |
|
645 | }
|
646 |
|
647 | enum MyEnum {
|
648 | Value = 0
|
649 | }
|
650 | ```
|
651 |
|
652 |
|
653 | ## [generic-anonymous](./test/programs/generic-anonymous)
|
654 |
|
655 | ```ts
|
656 | interface MyGeneric<A, B> {
|
657 | a: A;
|
658 | b: B;
|
659 | }
|
660 |
|
661 | export interface MyObject {
|
662 | value1: MyGeneric<string, number>;
|
663 | value2: MyGeneric<number, string>;
|
664 | }
|
665 | ```
|
666 |
|
667 |
|
668 | ## [generic-arrays](./test/programs/generic-arrays)
|
669 |
|
670 | ```ts
|
671 | export interface MyObject {
|
672 | numberArray: Array<number>;
|
673 | stringArray: ReadonlyArray<string>;
|
674 | }
|
675 | ```
|
676 |
|
677 |
|
678 | ## [generic-hell](./test/programs/generic-hell)
|
679 |
|
680 | ```ts
|
681 | export interface GenericA<A> {
|
682 | a: A;
|
683 | }
|
684 | export interface B {
|
685 | b: number;
|
686 | }
|
687 | export interface GenericC<C> {
|
688 | c: C;
|
689 | }
|
690 |
|
691 | export type SomeAlias<T> = SomeGeneric<T, T>;
|
692 | export interface SomeGeneric<A, B> {
|
693 | a: A;
|
694 | b: B;
|
695 | c: GenericA<A>;
|
696 | d: GenericC<B>;
|
697 | }
|
698 |
|
699 | export interface MyObject extends GenericC<GenericC<GenericC<GenericA<string>>>>, B {
|
700 | someGeneric: SomeGeneric<1, 2>;
|
701 | someAlias: SomeAlias<"alias">;
|
702 | }
|
703 | ```
|
704 |
|
705 |
|
706 | ## [generic-multiargs](./test/programs/generic-multiargs)
|
707 |
|
708 | ```ts
|
709 | export interface MyGeneric<A, B> {
|
710 | a: A;
|
711 | b: B;
|
712 | }
|
713 |
|
714 | export interface MyObject {
|
715 | value1: MyGeneric<string, number>;
|
716 | value2: MyGeneric<number, string>;
|
717 | }
|
718 | ```
|
719 |
|
720 |
|
721 | ## [generic-multiple](./test/programs/generic-multiple)
|
722 |
|
723 | ```ts
|
724 | export interface MyGeneric<T> {
|
725 | field: T;
|
726 | }
|
727 |
|
728 | export interface MyObject {
|
729 | value1: MyGeneric<number>;
|
730 | value2: MyGeneric<string>;
|
731 | }
|
732 | ```
|
733 |
|
734 |
|
735 | ## [generic-recursive](./test/programs/generic-recursive)
|
736 |
|
737 | ```ts
|
738 | export interface MyGeneric<A, B> {
|
739 | field: MyGeneric<B, A>;
|
740 | }
|
741 |
|
742 | export interface MyObject {
|
743 | value: MyGeneric<string, number>;
|
744 | }
|
745 | ```
|
746 |
|
747 |
|
748 | ## [generic-simple](./test/programs/generic-simple)
|
749 |
|
750 | ```ts
|
751 | export interface MyGeneric<T> {
|
752 | field: T;
|
753 | }
|
754 |
|
755 | export interface MyObject {
|
756 | value: MyGeneric<number>;
|
757 | }
|
758 | ```
|
759 |
|
760 |
|
761 | ## [ignored-required](./test/programs/ignored-required)
|
762 |
|
763 | ```ts
|
764 | interface MyObject {
|
765 | /**
|
766 | * @ignore
|
767 | */
|
768 | ignored: boolean;
|
769 |
|
770 | /**
|
771 | * @ignore
|
772 | */
|
773 | ignoredOptional?: boolean;
|
774 |
|
775 | required: boolean;
|
776 | optional?: boolean;
|
777 | }
|
778 | ```
|
779 |
|
780 |
|
781 | ## [imports](./test/programs/imports)
|
782 |
|
783 | ```ts
|
784 |
|
785 | // This file imports "MyInterface" from the other 2 files
|
786 | // while also declaring a MyInterface type
|
787 |
|
788 | import { MyInterface as module1_MyInterface } from "./module1";
|
789 | import * as module2 from "./module2";
|
790 |
|
791 | class MyInterface {
|
792 | fieldInMain: number;
|
793 | }
|
794 |
|
795 | class MyObject {
|
796 | a: MyInterface;
|
797 | b: module1_MyInterface;
|
798 | c: module2.MyInterface;
|
799 | }
|
800 | ```
|
801 |
|
802 |
|
803 | ## [imports](./test/programs/imports)
|
804 |
|
805 | ```ts
|
806 |
|
807 | export class MyInterface {
|
808 | fieldInModule1: string;
|
809 | }
|
810 |
|
811 | ```
|
812 |
|
813 |
|
814 | ## [imports](./test/programs/imports)
|
815 |
|
816 | ```ts
|
817 |
|
818 | export class MyInterface {
|
819 | fieldInModule2: number;
|
820 | }
|
821 |
|
822 | ```
|
823 |
|
824 |
|
825 | ## [interface-extends](./test/programs/interface-extends)
|
826 |
|
827 | ```ts
|
828 | interface Base {
|
829 | propA: number;
|
830 | }
|
831 |
|
832 | export interface MyObject extends Base {
|
833 | propB: number;
|
834 | }
|
835 | ```
|
836 |
|
837 |
|
838 | ## [interface-extra-props](./test/programs/interface-extra-props)
|
839 |
|
840 | ```ts
|
841 | export interface MyObject {
|
842 | required: string;
|
843 | optional?: number;
|
844 | [name: string]: string|number;
|
845 | }
|
846 | ```
|
847 |
|
848 |
|
849 | ## [interface-multi](./test/programs/interface-multi)
|
850 |
|
851 | ```ts
|
852 | interface MyObject {
|
853 | subA: MySubObject;
|
854 | subB: MySubObject;
|
855 | }
|
856 | interface MySubObject {
|
857 | propA: number;
|
858 | propB: number;
|
859 | }
|
860 | ```
|
861 |
|
862 |
|
863 | ## [interface-recursion](./test/programs/interface-recursion)
|
864 |
|
865 | ```ts
|
866 | interface MyObject {
|
867 | propA: number;
|
868 | propB: MyObject;
|
869 | }
|
870 | ```
|
871 |
|
872 |
|
873 | ## [interface-single](./test/programs/interface-single)
|
874 |
|
875 | ```ts
|
876 | export interface MyObject {
|
877 | propA: number;
|
878 | propB: number;
|
879 | }
|
880 | ```
|
881 |
|
882 |
|
883 | ## [map-types](./test/programs/map-types)
|
884 |
|
885 | ```ts
|
886 |
|
887 | interface MyType {}
|
888 |
|
889 | interface MyMap1 {
|
890 | [id: string]: MyType;
|
891 | }
|
892 |
|
893 | /**
|
894 | * The additionalProperties annotation should be ignored
|
895 | * @additionalProperties false
|
896 | */
|
897 | interface MyMap2 {
|
898 | [id: string]: (string | number);
|
899 | }
|
900 |
|
901 | type MyMap3 = Readonly<MyMap2>;
|
902 |
|
903 | interface MyObject {
|
904 | map1: MyMap1;
|
905 | map2: MyMap2;
|
906 | map3: MyMap3;
|
907 | }
|
908 | ```
|
909 |
|
910 |
|
911 | ## [module-interface-deep](./test/programs/module-interface-deep)
|
912 |
|
913 | ```ts
|
914 | module MyModule {
|
915 | export interface Def {
|
916 | nest: Def;
|
917 | prev: MyModule.Def;
|
918 | propA: SubModule.HelperA;
|
919 | propB: SubModule.HelperB;
|
920 | }
|
921 | export module SubModule {
|
922 | export interface HelperA {
|
923 | propA: number;
|
924 | propB: HelperB;
|
925 | }
|
926 | export interface HelperB {
|
927 | propA: SubModule.HelperA;
|
928 | propB: Def;
|
929 | }
|
930 | }
|
931 | }
|
932 | ```
|
933 |
|
934 |
|
935 | ## [module-interface-single](./test/programs/module-interface-single)
|
936 |
|
937 | ```ts
|
938 | module MyModule {
|
939 | interface MyObject {
|
940 | propA: number;
|
941 | propB: number;
|
942 | }
|
943 | }
|
944 | ```
|
945 |
|
946 |
|
947 | ## [namespace](./test/programs/namespace)
|
948 |
|
949 | ```ts
|
950 | export namespace Types {
|
951 | export const X: "x" = "x";
|
952 | export const Y: "y" = "y";
|
953 | }
|
954 |
|
955 | export type Type = typeof Types.X | typeof Types.Y;
|
956 | ```
|
957 |
|
958 |
|
959 | ## [namespace-deep-1](./test/programs/namespace-deep-1)
|
960 |
|
961 | ```ts
|
962 | namespace RootNamespace {
|
963 | export interface Def {
|
964 | nest: Def;
|
965 | prev: RootNamespace.Def;
|
966 |
|
967 | propA: SubNamespace.HelperA;
|
968 | propB: SubNamespace.HelperB;
|
969 | }
|
970 |
|
971 | export namespace SubNamespace {
|
972 | export interface HelperA {
|
973 | propA: number;
|
974 | propB: HelperB;
|
975 | }
|
976 | export interface HelperB {
|
977 | propA: SubNamespace.HelperA;
|
978 | propB: Def;
|
979 | }
|
980 | }
|
981 | }
|
982 | ```
|
983 |
|
984 |
|
985 | ## [namespace-deep-2](./test/programs/namespace-deep-2)
|
986 |
|
987 | ```ts
|
988 | namespace RootNamespace {
|
989 | export interface Def {
|
990 | nest: Def;
|
991 | prev: RootNamespace.Def;
|
992 |
|
993 | propA: SubNamespace.HelperA;
|
994 | propB: SubNamespace.HelperB;
|
995 | }
|
996 |
|
997 | export namespace SubNamespace {
|
998 | export interface HelperA {
|
999 | propA: number;
|
1000 | propB: HelperB;
|
1001 | }
|
1002 | export interface HelperB {
|
1003 | propA: SubNamespace.HelperA;
|
1004 | propB: Def;
|
1005 | }
|
1006 | }
|
1007 | }
|
1008 | ```
|
1009 |
|
1010 |
|
1011 | ## [never](./test/programs/never)
|
1012 |
|
1013 | ```ts
|
1014 | export interface Never {
|
1015 | neverProp: never;
|
1016 | propA: string;
|
1017 | }
|
1018 | ```
|
1019 |
|
1020 |
|
1021 | ## [object-numeric-index](./test/programs/object-numeric-index)
|
1022 |
|
1023 | ```ts
|
1024 | interface IndexInterface {
|
1025 | [index: number]: number;
|
1026 | }
|
1027 | ```
|
1028 |
|
1029 |
|
1030 | ## [object-numeric-index-as-property](./test/programs/object-numeric-index-as-property)
|
1031 |
|
1032 | ```ts
|
1033 | interface Target {
|
1034 | objAnonymous: {
|
1035 | [index: number]: number;
|
1036 | };
|
1037 | objInterface: IndexInterface;
|
1038 | indexInType: { [index in number]?: number };
|
1039 | indexInInline: { [index in number]: number };
|
1040 | indexInPartialType: IndexInPartial;
|
1041 | indexInPartialInline: { [index in number]?: number };
|
1042 | }
|
1043 | interface IndexInterface {
|
1044 | [index: number]: number;
|
1045 | }
|
1046 |
|
1047 | type IndexIn = { [index in number]: number };
|
1048 | type IndexInPartial = { [index in number]?: number };
|
1049 | ```
|
1050 |
|
1051 |
|
1052 | ## [optionals](./test/programs/optionals)
|
1053 |
|
1054 | ```ts
|
1055 | interface MyObject {
|
1056 | required:number;
|
1057 | optional?:number;
|
1058 | }
|
1059 | ```
|
1060 |
|
1061 |
|
1062 | ## [optionals-derived](./test/programs/optionals-derived)
|
1063 |
|
1064 | ```ts
|
1065 | interface MyBase {
|
1066 | baseRequired : number;
|
1067 | baseOptional?: number;
|
1068 | }
|
1069 |
|
1070 | interface MyDerived extends MyBase {
|
1071 | derivedRequired : number;
|
1072 | derivedOptional?: number;
|
1073 | }
|
1074 | ```
|
1075 |
|
1076 |
|
1077 | ## [private-members](./test/programs/private-members)
|
1078 |
|
1079 | ```ts
|
1080 | export class MyObject {
|
1081 | publicMember: string;
|
1082 | private privateMember: string;
|
1083 | }
|
1084 | ```
|
1085 |
|
1086 |
|
1087 | ## [strict-null-checks](./test/programs/strict-null-checks)
|
1088 |
|
1089 | ```ts
|
1090 |
|
1091 | class MyObject {
|
1092 | val: number;
|
1093 | valNullable: number | null;
|
1094 | valUndef: number | undefined;
|
1095 | valOpt?: number;
|
1096 |
|
1097 | valTrueOpt?: true;
|
1098 | valTrueOrNull: true|null;
|
1099 | valTrue: true|true; // twice to check that it will appear only once
|
1100 | }
|
1101 | ```
|
1102 |
|
1103 |
|
1104 | ## [string-literals](./test/programs/string-literals)
|
1105 |
|
1106 | ```ts
|
1107 | type result = "ok" | "fail" | "abort" | "";
|
1108 |
|
1109 | class MyObject {
|
1110 | foo: result;
|
1111 | bar: result | string;
|
1112 | }
|
1113 | ```
|
1114 |
|
1115 |
|
1116 | ## [string-literals-inline](./test/programs/string-literals-inline)
|
1117 |
|
1118 | ```ts
|
1119 | class MyObject {
|
1120 | foo: "ok" | "fail" | "abort" | "";
|
1121 | bar: "ok" | "fail" | "abort" | string;
|
1122 | }
|
1123 | ```
|
1124 |
|
1125 |
|
1126 | ## [tsconfig](./test/programs/tsconfig)
|
1127 |
|
1128 | ```ts
|
1129 | // This file is ignored.
|
1130 |
|
1131 | export interface Excluded {
|
1132 | a: string;
|
1133 | }
|
1134 | ```
|
1135 |
|
1136 |
|
1137 | ## [tsconfig](./test/programs/tsconfig)
|
1138 |
|
1139 | ```ts
|
1140 | // This file is included by tsconfig.json and --include.
|
1141 |
|
1142 | export interface IncludedAlways {
|
1143 | a: string;
|
1144 | };
|
1145 | ```
|
1146 |
|
1147 |
|
1148 | ## [tsconfig](./test/programs/tsconfig)
|
1149 |
|
1150 | ```ts
|
1151 | // This file is included by tsconfig.json.
|
1152 |
|
1153 | export interface IncludedOnlyByTsConfig {
|
1154 | a: string;
|
1155 | };
|
1156 | ```
|
1157 |
|
1158 |
|
1159 | ## [type-alias-schema-override](./test/programs/type-alias-schema-override)
|
1160 |
|
1161 | ```ts
|
1162 | interface All {}
|
1163 |
|
1164 | type Some = Partial<All>;
|
1165 |
|
1166 | interface MyObject {
|
1167 | some?: Some;
|
1168 | }
|
1169 | ```
|
1170 |
|
1171 |
|
1172 | ## [type-alias-single](./test/programs/type-alias-single)
|
1173 |
|
1174 | ```ts
|
1175 | type MyString = string;
|
1176 | ```
|
1177 |
|
1178 |
|
1179 | ## [type-alias-single-annotated](./test/programs/type-alias-single-annotated)
|
1180 |
|
1181 | ```ts
|
1182 | /**
|
1183 | * This is a description
|
1184 | * @pattern ^mystring-[a-zA-Z0-9]+$
|
1185 | * @minLength 10
|
1186 | * @maxLength 24
|
1187 | */
|
1188 | type MyString = string;
|
1189 | ```
|
1190 |
|
1191 |
|
1192 | ## [type-aliases](./test/programs/type-aliases)
|
1193 |
|
1194 | ```ts
|
1195 | /**
|
1196 | * My string
|
1197 | */
|
1198 | type MyString = string;
|
1199 |
|
1200 | /**
|
1201 | * My type alias
|
1202 | */
|
1203 | type MyAlias = MySubObject;
|
1204 |
|
1205 | /**
|
1206 | * My sub object
|
1207 | */
|
1208 | interface MySubObject {
|
1209 | propA: number;
|
1210 | propB: number;
|
1211 | }
|
1212 |
|
1213 | /**
|
1214 | * My Object
|
1215 | */
|
1216 | interface MyObject {
|
1217 | primitive: MyString;
|
1218 | object: MySubObject;
|
1219 | alias: MyAlias;
|
1220 | }
|
1221 | ```
|
1222 |
|
1223 |
|
1224 | ## [type-aliases-alias-ref](./test/programs/type-aliases-alias-ref)
|
1225 |
|
1226 | ```ts
|
1227 |
|
1228 | interface MyObject {
|
1229 | prop: number;
|
1230 | }
|
1231 |
|
1232 | type MyAlias = MyObject;
|
1233 | ```
|
1234 |
|
1235 |
|
1236 | ## [type-aliases-alias-ref-topref](./test/programs/type-aliases-alias-ref-topref)
|
1237 |
|
1238 | ```ts
|
1239 |
|
1240 | interface MyObject {
|
1241 | prop: number;
|
1242 | }
|
1243 |
|
1244 | type MyAlias = MyObject;
|
1245 | ```
|
1246 |
|
1247 |
|
1248 | ## [type-aliases-anonymous](./test/programs/type-aliases-anonymous)
|
1249 |
|
1250 | ```ts
|
1251 | export type MyExportString = string;
|
1252 | type MyPrivateString = string;
|
1253 |
|
1254 | export interface MyObject {
|
1255 | export: MyExportString;
|
1256 | private: MyPrivateString;
|
1257 | }
|
1258 | ```
|
1259 |
|
1260 |
|
1261 | ## [type-aliases-fixed-size-array](./test/programs/type-aliases-fixed-size-array)
|
1262 |
|
1263 | ```ts
|
1264 | type MyFixedSizeArray = [string, number];
|
1265 |
|
1266 | ```
|
1267 |
|
1268 |
|
1269 | ## [type-aliases-local-namespace](./test/programs/type-aliases-local-namespace)
|
1270 |
|
1271 | ```ts
|
1272 | namespace A {
|
1273 | export interface A { a: any; }
|
1274 | }
|
1275 | namespace B {
|
1276 | export interface B { b: any; }
|
1277 | }
|
1278 | namespace C {
|
1279 | import A = B.B;
|
1280 | export interface C { c: A; }
|
1281 | }
|
1282 | namespace D {
|
1283 | import A = C.C;
|
1284 | export interface D { d: A; }
|
1285 | }
|
1286 |
|
1287 | export interface MyObject extends D.D {}
|
1288 | ```
|
1289 |
|
1290 |
|
1291 | ## [type-aliases-local-namsepace](./test/programs/type-aliases-local-namsepace)
|
1292 |
|
1293 | ```ts
|
1294 | namespace A {
|
1295 | export interface A {a: any;}
|
1296 | }
|
1297 | namespace B {
|
1298 | export interface B {b: any;}
|
1299 | }
|
1300 | namespace C {
|
1301 | import A = B.B;
|
1302 | export interface C {c: A;}
|
1303 | }
|
1304 | namespace D {
|
1305 | import A = C.C;
|
1306 | export interface D {d: A;}
|
1307 | }
|
1308 |
|
1309 | interface MyObject extends D.D {}
|
1310 | ```
|
1311 |
|
1312 |
|
1313 | ## [type-aliases-mixed](./test/programs/type-aliases-mixed)
|
1314 |
|
1315 | ```ts
|
1316 | export type MyString = string;
|
1317 |
|
1318 | export interface MySubObject {
|
1319 | propA: number;
|
1320 | propB: number;
|
1321 | }
|
1322 |
|
1323 | export interface MyObject {
|
1324 | primitive: MyString;
|
1325 | object: MySubObject;
|
1326 | }
|
1327 | ```
|
1328 |
|
1329 |
|
1330 | ## [type-aliases-multitype-array](./test/programs/type-aliases-multitype-array)
|
1331 |
|
1332 | ```ts
|
1333 |
|
1334 | type BasicArray = (string | number)[];
|
1335 |
|
1336 | interface MyObject {
|
1337 | array: BasicArray;
|
1338 | }
|
1339 |
|
1340 | type MyArray = (string | MyObject)[];
|
1341 | ```
|
1342 |
|
1343 |
|
1344 | ## [type-aliases-object](./test/programs/type-aliases-object)
|
1345 |
|
1346 | ```ts
|
1347 |
|
1348 | export interface MyObject {
|
1349 | number: number;
|
1350 | string: string;
|
1351 | }
|
1352 |
|
1353 | export type MyAlias = MyObject;
|
1354 | ```
|
1355 |
|
1356 |
|
1357 | ## [type-aliases-partial](./test/programs/type-aliases-partial)
|
1358 |
|
1359 | ```ts
|
1360 | export interface Foo {
|
1361 | x: number;
|
1362 | y: number;
|
1363 | }
|
1364 |
|
1365 | export interface Bar {
|
1366 | a: number;
|
1367 | b: number;
|
1368 | }
|
1369 |
|
1370 | export interface MyObject {
|
1371 | foo: Partial<Foo>;
|
1372 | bar: Partial<Bar>;
|
1373 | }
|
1374 | ```
|
1375 |
|
1376 |
|
1377 | ## [type-aliases-primitive](./test/programs/type-aliases-primitive)
|
1378 |
|
1379 | ```ts
|
1380 | export type MyString = string;
|
1381 | ```
|
1382 |
|
1383 |
|
1384 | ## [type-aliases-recursive-alias-topref](./test/programs/type-aliases-recursive-alias-topref)
|
1385 |
|
1386 | ```ts
|
1387 |
|
1388 | interface MyObject {
|
1389 | alias: MyAlias;
|
1390 | self: MyObject;
|
1391 | }
|
1392 |
|
1393 | type MyAlias = MyObject;
|
1394 | ```
|
1395 |
|
1396 |
|
1397 | ## [type-aliases-recursive-anonymous](./test/programs/type-aliases-recursive-anonymous)
|
1398 |
|
1399 | ```ts
|
1400 | interface MyObject {
|
1401 | alias: MyAlias;
|
1402 | self: MyObject;
|
1403 | }
|
1404 |
|
1405 | export type MyAlias = MyObject;
|
1406 | ```
|
1407 |
|
1408 |
|
1409 | ## [type-aliases-recursive-export](./test/programs/type-aliases-recursive-export)
|
1410 |
|
1411 | ```ts
|
1412 | export interface MyObject {
|
1413 | alias: MyAlias;
|
1414 | self: MyObject;
|
1415 | }
|
1416 |
|
1417 | export type MyAlias = MyObject;
|
1418 | ```
|
1419 |
|
1420 |
|
1421 | ## [type-aliases-recursive-object-topref](./test/programs/type-aliases-recursive-object-topref)
|
1422 |
|
1423 | ```ts
|
1424 |
|
1425 | interface MyObject {
|
1426 | alias: MyAlias;
|
1427 | self: MyObject;
|
1428 | }
|
1429 |
|
1430 | type MyAlias = MyObject;
|
1431 | ```
|
1432 |
|
1433 |
|
1434 | ## [type-aliases-tuple](./test/programs/type-aliases-tuple)
|
1435 |
|
1436 | ```ts
|
1437 | export type MyTuple = [string, number];
|
1438 | ```
|
1439 |
|
1440 |
|
1441 | ## [type-aliases-tuple-of-variable-length](./test/programs/type-aliases-tuple-of-variable-length)
|
1442 |
|
1443 | ```ts
|
1444 | export type MyTuple = [string, number, boolean?];
|
1445 | ```
|
1446 |
|
1447 |
|
1448 | ## [type-aliases-tuple-with-rest-element](./test/programs/type-aliases-tuple-with-rest-element)
|
1449 |
|
1450 | ```ts
|
1451 | export type MyTuple = [string, ...number[]];
|
1452 | ```
|
1453 |
|
1454 |
|
1455 | ## [type-aliases-union](./test/programs/type-aliases-union)
|
1456 |
|
1457 | ```ts
|
1458 |
|
1459 | type BasicArray = (string | number)[];
|
1460 |
|
1461 | export interface MyObject {
|
1462 | array: BasicArray;
|
1463 | }
|
1464 |
|
1465 | export type MyUnion = (string | MyObject)[];
|
1466 | ```
|
1467 |
|
1468 |
|
1469 | ## [type-aliases-union-namespace](./test/programs/type-aliases-union-namespace)
|
1470 |
|
1471 | ```ts
|
1472 |
|
1473 | export namespace Cardinal {
|
1474 | export const NORTH: "north" = "north";
|
1475 | export const SOUTH: "south" = "south";
|
1476 | export const EAST: "east" = "east";
|
1477 | export const WEST: "west" = "west";
|
1478 | }
|
1479 |
|
1480 | export type Cardinal = typeof Cardinal.NORTH | typeof Cardinal.SOUTH | typeof Cardinal.EAST | typeof Cardinal.WEST;
|
1481 |
|
1482 | export interface MyModel {
|
1483 | direction: Cardinal;
|
1484 | }
|
1485 | ```
|
1486 |
|
1487 |
|
1488 | ## [type-anonymous](./test/programs/type-anonymous)
|
1489 |
|
1490 | ```ts
|
1491 | interface MyObject {
|
1492 | FieldWithAnonType: {
|
1493 | SubfieldA: number;
|
1494 | SubfieldB: (string | number);
|
1495 | SubfieldC: {
|
1496 | SubsubfieldA: number[];
|
1497 | }
|
1498 | };
|
1499 | }
|
1500 | ```
|
1501 |
|
1502 |
|
1503 | ## [type-default-number-as-integer](./test/programs/type-default-number-as-integer)
|
1504 |
|
1505 | ```ts
|
1506 | interface MyObject {
|
1507 | as_integer: number;
|
1508 |
|
1509 | /** @TJS-type number */
|
1510 | as_number: number;
|
1511 | }
|
1512 | ```
|
1513 |
|
1514 |
|
1515 | ## [type-function](./test/programs/type-function)
|
1516 |
|
1517 | ```ts
|
1518 | interface MyObject {
|
1519 | myFunction: Function;
|
1520 | }```
|
1521 |
|
1522 |
|
1523 | ## [type-globalThis](./test/programs/type-globalThis)
|
1524 |
|
1525 | ```ts
|
1526 | export type Test = typeof globalThis;
|
1527 | ```
|
1528 |
|
1529 |
|
1530 | ## [type-intersection](./test/programs/type-intersection)
|
1531 |
|
1532 | ```ts
|
1533 | interface Type1 {
|
1534 | value1: string;
|
1535 | value2: number;
|
1536 | }
|
1537 | interface Type2 {
|
1538 | value2: number;
|
1539 | value3: boolean;
|
1540 | }
|
1541 |
|
1542 | interface MyObject {
|
1543 | value: Type1 & Type2;
|
1544 | }
|
1545 | ```
|
1546 |
|
1547 |
|
1548 | ## [type-intersection-recursive](./test/programs/type-intersection-recursive)
|
1549 |
|
1550 | ```ts
|
1551 | interface ChildFoo {
|
1552 | }
|
1553 |
|
1554 | interface Foo {
|
1555 | readonly childFoos: Foo & ChildFoo;
|
1556 | }
|
1557 | ```
|
1558 |
|
1559 |
|
1560 | ## [type-mapped-types](./test/programs/type-mapped-types)
|
1561 |
|
1562 | ```ts
|
1563 | type Keys = "str1" | "str2";
|
1564 |
|
1565 | type MyMappedType = {
|
1566 | [key in Keys]: string;
|
1567 | };
|
1568 | ```
|
1569 |
|
1570 |
|
1571 | ## [type-no-aliases-recursive-topref](./test/programs/type-no-aliases-recursive-topref)
|
1572 |
|
1573 | ```ts
|
1574 |
|
1575 | interface MyObject {
|
1576 | alias: MyAlias;
|
1577 | self: MyObject;
|
1578 | }
|
1579 |
|
1580 | type MyAlias = MyObject;
|
1581 | ```
|
1582 |
|
1583 |
|
1584 | ## [type-nullable](./test/programs/type-nullable)
|
1585 |
|
1586 | ```ts
|
1587 |
|
1588 | /** @nullable */
|
1589 | type MyType1 = string;
|
1590 |
|
1591 | /** @nullable */
|
1592 | type MyType2 = string | number;
|
1593 |
|
1594 | /** @nullable */
|
1595 | type MyType3 = string | number[];
|
1596 |
|
1597 | /** @nullable */
|
1598 | type MyType4 = number[];
|
1599 |
|
1600 | type Ref = { foo: number };
|
1601 |
|
1602 | /** @nullable */
|
1603 | type MyType5 = Ref;
|
1604 |
|
1605 | interface MyType6 {};
|
1606 |
|
1607 | interface MyObject {
|
1608 | var1: MyType1;
|
1609 | var2: MyType2;
|
1610 | var3: MyType3;
|
1611 | var4: MyType4;
|
1612 | var5: MyType5;
|
1613 |
|
1614 | /**
|
1615 | * @nullable
|
1616 | */
|
1617 | var6: MyType6;
|
1618 | var7: MyType6;
|
1619 | }
|
1620 | ```
|
1621 |
|
1622 |
|
1623 | ## [type-primitives](./test/programs/type-primitives)
|
1624 |
|
1625 | ```ts
|
1626 | /* tslint:disable:no-inferrable-types */
|
1627 |
|
1628 | // Special type, should not appear in the schema
|
1629 | type integer = number;
|
1630 |
|
1631 | class MyObject {
|
1632 |
|
1633 | boolean1: boolean = true;
|
1634 |
|
1635 | number1: number = 1;
|
1636 |
|
1637 | /** @TJS-type integer */
|
1638 | integer1: number = 1;
|
1639 | integer2: integer = 1;
|
1640 |
|
1641 | string1: string = "defaultValue";
|
1642 |
|
1643 | array1: Array<any> = null;
|
1644 | array2: Array<number> = null;
|
1645 |
|
1646 | object1: any = null;
|
1647 | object2: {} = null;
|
1648 | object3: object = null;
|
1649 |
|
1650 | }
|
1651 | ```
|
1652 |
|
1653 |
|
1654 | ## [type-recursive](./test/programs/type-recursive)
|
1655 |
|
1656 | ```ts
|
1657 | /**
|
1658 | * A recursive type
|
1659 | */
|
1660 | export type TestChildren = TestChild | Array<TestChild | TestChildren>;
|
1661 |
|
1662 | interface TestChild {
|
1663 | type: string;
|
1664 | }
|
1665 | ```
|
1666 |
|
1667 |
|
1668 | ## [type-union](./test/programs/type-union)
|
1669 |
|
1670 | ```ts
|
1671 |
|
1672 | // Simple union (generates "type": [...])
|
1673 | type MyType1 = string | number;
|
1674 |
|
1675 | // Non-simple union (generates a "oneOf"/"anyOf")
|
1676 | type MyType2 = string | number[];
|
1677 |
|
1678 | interface MyObject {
|
1679 | var1: MyType1;
|
1680 | var2: MyType2;
|
1681 | }
|
1682 | ```
|
1683 |
|
1684 |
|
1685 | ## [type-union-tagged](./test/programs/type-union-tagged)
|
1686 |
|
1687 | ```ts
|
1688 |
|
1689 | interface Square {
|
1690 | kind: "square";
|
1691 | size: number;
|
1692 | }
|
1693 |
|
1694 | interface Rectangle {
|
1695 | kind: "rectangle";
|
1696 | width: number;
|
1697 | height: number;
|
1698 | }
|
1699 |
|
1700 | interface Circle {
|
1701 | kind: "circle";
|
1702 | radius: number;
|
1703 | }
|
1704 |
|
1705 | type Shape = Square | Rectangle | Circle;
|
1706 | ```
|
1707 |
|
1708 |
|
1709 | ## [typeof-keyword](./test/programs/typeof-keyword)
|
1710 |
|
1711 | ```ts
|
1712 | interface MyObject {
|
1713 | foo: () => string;
|
1714 | }
|
1715 | ```
|
1716 |
|
1717 |
|
1718 | ## [unique-names](./test/programs/unique-names)
|
1719 |
|
1720 | ```ts
|
1721 | import "./other";
|
1722 |
|
1723 | class MyObject {
|
1724 | is: "MyObject_1";
|
1725 | }
|
1726 | ```
|
1727 |
|
1728 |
|
1729 | ## [unique-names](./test/programs/unique-names)
|
1730 |
|
1731 | ```ts
|
1732 | class MyObject {
|
1733 | is: "MyObject_2";
|
1734 | }
|
1735 | ```
|
1736 |
|
1737 |
|
1738 | ## [unique-names-multiple-subdefinitions](./test/programs/unique-names-multiple-subdefinitions)
|
1739 |
|
1740 | ```ts
|
1741 | import "./other";
|
1742 |
|
1743 | class SubObject {
|
1744 | is: "SubObject_1";
|
1745 | }
|
1746 |
|
1747 | class MyObject {
|
1748 | sub: SubObject;
|
1749 | }
|
1750 | ```
|
1751 |
|
1752 |
|
1753 | ## [unique-names-multiple-subdefinitions](./test/programs/unique-names-multiple-subdefinitions)
|
1754 |
|
1755 | ```ts
|
1756 | class SubObject {
|
1757 | is: "SubObject_2";
|
1758 | }
|
1759 | ```
|
1760 |
|
1761 |
|
1762 | ## [user-symbols](./test/programs/user-symbols)
|
1763 |
|
1764 | ```ts
|
1765 | export interface Context {
|
1766 | ip: string;
|
1767 | }
|
1768 | ```
|
1769 |
|
1770 |
|
1771 | ## [user-validation-keywords](./test/programs/user-validation-keywords)
|
1772 |
|
1773 | ```ts
|
1774 | export interface MyObject {
|
1775 | /**
|
1776 | * Must be 'first' or 'last'
|
1777 | *
|
1778 | * @minLength 1
|
1779 | * @chance {
|
1780 | * "pickone": [ [ "first", "last" ] ]
|
1781 | * }
|
1782 | * @ignoreThis 2
|
1783 | * @important
|
1784 | */
|
1785 | name: string;
|
1786 | }
|
1787 | ```
|
1788 |
|
1789 |
|