@@ -17,7 +17,7 @@ export function getDefaultArgs() {
17
17
usePropertyOrder : false ,
18
18
generateRequired : false ,
19
19
strictNullChecks : false ,
20
- out : undefined
20
+ out : undefined as string
21
21
} ;
22
22
}
23
23
@@ -62,7 +62,7 @@ export class JsonSchemaGenerator {
62
62
const annotationTokens = annotation [ 0 ] . split ( " " ) ;
63
63
let keyword : string = annotationTokens [ 0 ] . slice ( 1 ) ;
64
64
const path = keyword . split ( "." ) ;
65
- let context = null ;
65
+ let context : string = null ;
66
66
67
67
// TODO: paths etc. originate from Typson, not supported atm.
68
68
if ( path . length > 1 ) {
@@ -102,7 +102,7 @@ export class JsonSchemaGenerator {
102
102
* @param to {object} the destination variable or definition.
103
103
* @returns {string } the full comment minus the beginning description part.
104
104
*/
105
- private copyDescription ( comment : string , to ) : string {
105
+ private copyDescription ( comment : string , to : { description : string } ) : string {
106
106
const delimiter = "@" ;
107
107
const delimiterIndex = comment . indexOf ( delimiter ) ;
108
108
const description = comment . slice ( 0 , delimiterIndex < 0 ? comment . length : delimiterIndex ) ;
@@ -254,7 +254,7 @@ export class JsonSchemaGenerator {
254
254
definition . default = initial . getText ( ) ;
255
255
} else {
256
256
try {
257
- const sandbox = { sandboxvar : null } ;
257
+ const sandbox = { sandboxvar : null as ts . Expression } ;
258
258
vm . runInNewContext ( "sandboxvar=" + initial . getText ( ) , sandbox ) ;
259
259
260
260
initial = sandbox . sandboxvar ;
@@ -280,7 +280,7 @@ export class JsonSchemaGenerator {
280
280
var enumValues : any [ ] = [ ] ;
281
281
let enumTypes : string [ ] = [ ] ;
282
282
283
- const addType = ( type ) => {
283
+ const addType = ( type : string ) => {
284
284
if ( enumTypes . indexOf ( type ) === - 1 ) {
285
285
enumTypes . push ( type ) ;
286
286
}
@@ -333,17 +333,17 @@ export class JsonSchemaGenerator {
333
333
}
334
334
335
335
private getUnionDefinition ( unionType : ts . UnionType , prop : ts . Symbol , tc : ts . TypeChecker , unionModifier : string , definition : any ) : any {
336
- const enumValues = [ ] ;
337
- const simpleTypes = [ ] ;
338
- const schemas = [ ] ;
336
+ const enumValues : ( string | number | boolean ) [ ] = [ ] ;
337
+ const simpleTypes : string [ ] = [ ] ;
338
+ const schemas : any [ ] = [ ] ;
339
339
340
- const addSimpleType = ( type ) => {
340
+ const addSimpleType = ( type : string ) => {
341
341
if ( simpleTypes . indexOf ( type ) === - 1 ) {
342
342
simpleTypes . push ( type ) ;
343
343
}
344
344
} ;
345
345
346
- const addEnumValue = ( val ) => {
346
+ const addEnumValue = ( val : string | number | boolean ) => {
347
347
if ( enumValues . indexOf ( val ) === - 1 ) {
348
348
enumValues . push ( val ) ;
349
349
}
@@ -761,7 +761,7 @@ export function programFromConfig(configFileName: string) {
761
761
}
762
762
export function exec ( filePattern : string , fullTypeName : string , args = getDefaultArgs ( ) ) {
763
763
let program : ts . Program ;
764
- if ( path . basename ( filePattern ) === "tsconfig.json" ) {
764
+ if ( path . basename ( filePattern ) === "tsconfig.json" ) {
765
765
program = programFromConfig ( filePattern ) ;
766
766
} else {
767
767
program = getProgramFromFiles ( glob . sync ( filePattern ) , {
@@ -772,9 +772,9 @@ export function exec(filePattern: string, fullTypeName: string, args = getDefaul
772
772
const definition = generateSchema ( program , fullTypeName , args ) ;
773
773
774
774
const json = stringify ( definition , { space : 4 } ) + "\n\n" ;
775
- if ( args . out ) {
776
- require ( "fs" ) . writeFile ( args . out , json , function ( err ) {
777
- if ( err ) {
775
+ if ( args . out ) {
776
+ require ( "fs" ) . writeFile ( args . out , json , function ( err : Error ) {
777
+ if ( err ) {
778
778
console . error ( "Unable to write output file: " + err . message ) ;
779
779
}
780
780
} ) ;
0 commit comments