Skip to content

Commit 1aa10cb

Browse files
committed
Enable noImplicitAny
1 parent 1fc5786 commit 1aa10cb

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"experimentalDecorators": true,
88
"emitDecoratorMetadata": true,
99
"declaration": true,
10-
"noImplicitAny": false,
10+
"noImplicitAny": true,
11+
"suppressImplicitAnyIndexErrors": true,
1112
"removeComments": true,
1213
"noLib": false,
1314
"preserveConstEnums": true,

typescript-json-schema.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function getDefaultArgs() {
1717
usePropertyOrder: false,
1818
generateRequired: false,
1919
strictNullChecks: false,
20-
out: undefined
20+
out: undefined as string
2121
};
2222
}
2323

@@ -62,7 +62,7 @@ export class JsonSchemaGenerator {
6262
const annotationTokens = annotation[0].split(" ");
6363
let keyword: string = annotationTokens[0].slice(1);
6464
const path = keyword.split(".");
65-
let context = null;
65+
let context: string = null;
6666

6767
// TODO: paths etc. originate from Typson, not supported atm.
6868
if (path.length > 1) {
@@ -102,7 +102,7 @@ export class JsonSchemaGenerator {
102102
* @param to {object} the destination variable or definition.
103103
* @returns {string} the full comment minus the beginning description part.
104104
*/
105-
private copyDescription(comment: string, to): string {
105+
private copyDescription(comment: string, to: {description: string}): string {
106106
const delimiter = "@";
107107
const delimiterIndex = comment.indexOf(delimiter);
108108
const description = comment.slice(0, delimiterIndex < 0 ? comment.length : delimiterIndex);
@@ -254,7 +254,7 @@ export class JsonSchemaGenerator {
254254
definition.default = initial.getText();
255255
} else {
256256
try {
257-
const sandbox = { sandboxvar: null };
257+
const sandbox = { sandboxvar: null as ts.Expression };
258258
vm.runInNewContext("sandboxvar=" + initial.getText(), sandbox);
259259

260260
initial = sandbox.sandboxvar;
@@ -280,7 +280,7 @@ export class JsonSchemaGenerator {
280280
var enumValues: any[] = [];
281281
let enumTypes: string[] = [];
282282

283-
const addType = (type) => {
283+
const addType = (type: string) => {
284284
if (enumTypes.indexOf(type) === -1) {
285285
enumTypes.push(type);
286286
}
@@ -333,17 +333,17 @@ export class JsonSchemaGenerator {
333333
}
334334

335335
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[] = [];
339339

340-
const addSimpleType = (type) => {
340+
const addSimpleType = (type: string) => {
341341
if (simpleTypes.indexOf(type) === -1) {
342342
simpleTypes.push(type);
343343
}
344344
};
345345

346-
const addEnumValue = (val) => {
346+
const addEnumValue = (val: string | number | boolean) => {
347347
if (enumValues.indexOf(val) === -1) {
348348
enumValues.push(val);
349349
}
@@ -761,7 +761,7 @@ export function programFromConfig(configFileName: string) {
761761
}
762762
export function exec(filePattern: string, fullTypeName: string, args = getDefaultArgs()) {
763763
let program: ts.Program;
764-
if(path.basename(filePattern) === "tsconfig.json") {
764+
if (path.basename(filePattern) === "tsconfig.json") {
765765
program = programFromConfig(filePattern);
766766
} else {
767767
program = getProgramFromFiles(glob.sync(filePattern), {
@@ -772,9 +772,9 @@ export function exec(filePattern: string, fullTypeName: string, args = getDefaul
772772
const definition = generateSchema(program, fullTypeName, args);
773773

774774
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) {
778778
console.error("Unable to write output file: " + err.message);
779779
}
780780
});

0 commit comments

Comments
 (0)