File tree 2 files changed +16
-11
lines changed
2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,17 @@ export class TypeOperatorConverter extends ConverterTypeComponent implements Typ
11
11
*/
12
12
priority = 50 ;
13
13
14
+ /**
15
+ * add two more operators based on the references below:
16
+ * https://github.com/microsoft/TypeScript/blob/e83102134e5640abb78b0c62941b3b5003ab6c1a/src/compiler/types.ts#L1602
17
+ * https://github.com/TypeStrong/typedoc/blob/b7a5b2d5ea1ae088e9510783ede20e842b120d0f/src/lib/converter/types.ts#L375
18
+ */
19
+ private readonly supportedOperatorNames = {
20
+ [ ts . SyntaxKind . KeyOfKeyword ] : 'keyof' ,
21
+ [ ts . SyntaxKind . UniqueKeyword ] : 'unique' ,
22
+ [ ts . SyntaxKind . ReadonlyKeyword ] : 'readonly'
23
+ } as const ;
24
+
14
25
/**
15
26
* Test whether this converter can handle the given TypeScript node.
16
27
*/
@@ -28,7 +39,8 @@ export class TypeOperatorConverter extends ConverterTypeComponent implements Typ
28
39
convertNode ( context : Context , node : ts . TypeOperatorNode ) : TypeOperatorType | undefined {
29
40
const target = this . owner . convertType ( context , node . type ) ;
30
41
if ( target ) {
31
- return new TypeOperatorType ( target ) ;
42
+ const operator = this . supportedOperatorNames [ node . operator ] ;
43
+ return new TypeOperatorType ( target , operator ) ;
32
44
}
33
45
}
34
46
}
Original file line number Diff line number Diff line change @@ -14,15 +14,8 @@ export class TypeOperatorType extends Type {
14
14
*/
15
15
readonly type = 'typeOperator' ;
16
16
17
- target : Type ;
18
-
19
- // currently, there is only one type operator, this is always "keyof"
20
- // but, if more types will be added in the future we are ready.
21
- readonly operator = 'keyof' ;
22
-
23
- constructor ( target : Type ) {
17
+ constructor ( public target : Type , public operator : 'keyof' | 'unique' | 'readonly' ) {
24
18
super ( ) ;
25
- this . target = target ;
26
19
}
27
20
28
21
/**
@@ -31,7 +24,7 @@ export class TypeOperatorType extends Type {
31
24
* @return A clone of this type.
32
25
*/
33
26
clone ( ) : Type {
34
- return new TypeOperatorType ( this . target . clone ( ) ) ;
27
+ return new TypeOperatorType ( this . target . clone ( ) , this . operator ) ;
35
28
}
36
29
37
30
/**
@@ -45,7 +38,7 @@ export class TypeOperatorType extends Type {
45
38
return false ;
46
39
}
47
40
48
- return type . target . equals ( this . target ) ;
41
+ return type instanceof TypeOperatorType && type . operator === this . operator && type . target . equals ( this . target ) ;
49
42
}
50
43
51
44
/**
You can’t perform that action at this time.
0 commit comments