5
5
import zzzank .probejs .lang .typescript .Declaration ;
6
6
import zzzank .probejs .lang .typescript .ScriptDump ;
7
7
import zzzank .probejs .lang .typescript .code .Code ;
8
+ import zzzank .probejs .lang .typescript .code .member .TypeDecl ;
8
9
import zzzank .probejs .lang .typescript .code .type .Types ;
9
10
import zzzank .probejs .lang .typescript .code .type .js .JSPrimitiveType ;
10
11
import zzzank .probejs .plugin .ProbeJSPlugin ;
@@ -23,6 +24,8 @@ public class Primitives extends ProbeJSPlugin {
23
24
public static final JSPrimitiveType CHARACTER = Types .primitive ("character" );
24
25
public static final JSPrimitiveType CHAR_SEQUENCE = Types .primitive ("charseq" );
25
26
27
+ private static final JSPrimitiveType TS_NUMBER = Types .primitive ("Number" );
28
+ private static final JSPrimitiveType JS_NUMBER = Types .primitive ("number" );
26
29
27
30
static class JavaPrimitive extends Code {
28
31
private final String javaPrimitive ;
@@ -80,15 +83,19 @@ public void addPredefinedTypes(TypeConverter converter) {
80
83
81
84
@ Override
82
85
public void addGlobals (ScriptDump scriptDump ) {
86
+ var numberBoth = Types .and (JS_NUMBER , TS_NUMBER );
83
87
scriptDump .addGlobal ("primitives" ,
84
- JavaPrimitive .of ("long" , "Number" ),
85
- JavaPrimitive .of ("integer" , "Number" ),
86
- JavaPrimitive .of ("short" , "Number" ),
87
- JavaPrimitive .of ("byte" , "Number" ),
88
- JavaPrimitive .of ("double" , "Number" ),
89
- JavaPrimitive .of ("float" , "Number" ),
90
- JavaPrimitive .of ("character" , "String" ),
91
- JavaPrimitive .of ("charseq" , "String" )
88
+ //for number types, we can safely mark them as a primitive type instead of an interface
89
+ //because the classes that represent them are `final`, so there's no need of taking inheritance into account
90
+ new TypeDecl ("long" , numberBoth ),
91
+ new TypeDecl ("integer" , numberBoth ),
92
+ new TypeDecl ("short" , numberBoth ),
93
+ new TypeDecl ("byte" , numberBoth ),
94
+ new TypeDecl ("double" , numberBoth ),
95
+ new TypeDecl ("float" , numberBoth ),
96
+ //for CharSequence, we should NOT mark it as a primitive type, because of inheritance
97
+ JavaPrimitive .of ("character" , "String" ),
98
+ JavaPrimitive .of ("charseq" , "String" )
92
99
);
93
100
}
94
101
}
0 commit comments