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