File tree Expand file tree Collapse file tree 1 file changed +13
-15
lines changed
Expand file tree Collapse file tree 1 file changed +13
-15
lines changed Original file line number Diff line number Diff line change 1- using System . Linq ;
2- using KY . Core ;
1+ using KY . Core ;
32using KY . Generator . Output ;
43using KY . Generator . Templates ;
54using KY . Generator . Writers ;
65
7- namespace KY . Generator . TypeScript . Writers
6+ namespace KY . Generator . TypeScript . Writers ;
7+
8+ public class TypeScriptDictionaryWriter : IGenericTypeWriter
89{
9- public class TypeScriptDictionaryWriter : IGenericTypeWriter
10+ public void Write ( GenericTypeTemplate template , IOutputCache output )
1011 {
11- public void Write ( GenericTypeTemplate template , IOutputCache output )
12+ TypeTemplate keyType = template . Types . First ( ) ;
13+ TypeTemplate valueType = template . Types . Second ( ) ;
14+ if ( keyType . Name is "string" or "number" )
15+ {
16+ output . Add ( "Record<" ) . Add ( keyType ) . Add ( ", " ) . Add ( valueType ) . Add ( ">" ) ;
17+ }
18+ else
1219 {
13- TypeTemplate keyType = template . Types . First ( ) ;
14- TypeTemplate valueType = template . Types . Second ( ) ;
15- if ( keyType . Name is "string" or "number" )
16- {
17- output . Add ( $ "{{ [key: { keyType . Name } ]: { valueType . Name } ; }}") ;
18- }
19- else
20- {
21- output . Add ( $ "{{ /* unsupported type for key. Expected string or number. Got '{ keyType . Name } '. */ }}") ;
22- }
20+ output . Add ( $ "{{ /* unsupported type for key. Expected string or number. Got '{ keyType . Name } '. */ }}") ;
2321 }
2422 }
2523}
You can’t perform that action at this time.
0 commit comments