Browse Source

Turn on `noImplicitAny` flag - fixes #3 (#47)

iss58
Sam Verschueren 7 years ago
committed by Sindre Sorhus
parent
commit
ec9483abea
  1. 2
      package.json
  2. 6
      source/index.ts
  3. 2
      source/lib/operators/not.ts
  4. 2
      source/lib/predicates/array.ts
  5. 2
      source/lib/predicates/map.ts
  6. 2
      source/lib/predicates/predicate.ts
  7. 2
      source/lib/predicates/set.ts
  8. 2
      source/test/undefined.ts
  9. 2
      tsconfig.json

2
package.json

@ -49,7 +49,9 @@
"devDependencies": { "devDependencies": {
"@sindresorhus/is": "^0.7.0", "@sindresorhus/is": "^0.7.0",
"@types/highlight.js": "^9.12.2", "@types/highlight.js": "^9.12.2",
"@types/lodash.isequal": "^4.5.2",
"@types/node": "^8.0.31", "@types/node": "^8.0.31",
"@types/vali-date": "^1.0.0",
"add-module-exports-webpack-plugin": "^0.1.0", "add-module-exports-webpack-plugin": "^0.1.0",
"ava": "*", "ava": "*",
"awesome-typescript-loader": "^3.2.3", "awesome-typescript-loader": "^3.2.3",

6
source/index.ts

@ -1,5 +1,5 @@
import {ArgumentError} from './lib/argument-error'; import {ArgumentError} from './lib/argument-error';
import {Predicate, validatorSymbol} from './lib/predicates/predicate'; import {Predicate, validatorSymbol, Validator} from './lib/predicates/predicate';
import {StringPredicate} from './lib/predicates/string'; import {StringPredicate} from './lib/predicates/string';
import {NumberPredicate} from './lib/predicates/number'; import {NumberPredicate} from './lib/predicates/number';
import {BooleanPredicate} from './lib/predicates/boolean'; import {BooleanPredicate} from './lib/predicates/boolean';
@ -155,7 +155,9 @@ export interface Ow {
} }
const main = <T>(value: T, predicate: Predicate<T>) => { const main = <T>(value: T, predicate: Predicate<T>) => {
for (const {validator, message} of predicate[validatorSymbol]) { const validators: Validator<any>[] = (predicate as any)[validatorSymbol];
for (const {validator, message} of validators) {
const result = validator(value); const result = validator(value);
if (typeof result !== 'boolean' || !result) { if (typeof result !== 'boolean' || !result) {

2
source/lib/operators/not.ts

@ -14,7 +14,7 @@ export const not = <T extends Predicate>(predicate: T) => {
validator.message = (x: any) => `[NOT] ${message(x)}`; validator.message = (x: any) => `[NOT] ${message(x)}`;
validator.validator = (x: any) => !fn(x); validator.validator = (x: any) => !fn(x);
predicate[validatorSymbol].push(validator); (predicate as any)[validatorSymbol].push(validator);
return predicate; return predicate;
}; };

2
source/lib/predicates/array.ts

@ -1,4 +1,4 @@
import * as isEqual from 'lodash.isequal'; import isEqual = require('lodash.isequal'); // tslint:disable-line:no-require-imports
import ow from '../..'; import ow from '../..';
import {Predicate, Context} from './predicate'; import {Predicate, Context} from './predicate';

2
source/lib/predicates/map.ts

@ -1,4 +1,4 @@
import * as isEqual from 'lodash.isequal'; import isEqual = require('lodash.isequal'); // tslint:disable-line:no-require-imports
import {Predicate, Context} from './predicate'; import {Predicate, Context} from './predicate';
import hasItems from '../utils/has-items'; import hasItems from '../utils/has-items';
import ofType from '../utils/of-type'; import ofType from '../utils/of-type';

2
source/lib/predicates/predicate.ts

@ -33,7 +33,7 @@ export class Predicate<T = any> {
) { ) {
this.addValidator({ this.addValidator({
message: value => `Expected argument to be of type \`${type}\` but received type \`${is(value)}\``, message: value => `Expected argument to be of type \`${type}\` but received type \`${is(value)}\``,
validator: value => is[type](value) validator: value => (is as any)[type](value)
}); });
} }

2
source/lib/predicates/set.ts

@ -1,4 +1,4 @@
import * as isEqual from 'lodash.isequal'; import isEqual = require('lodash.isequal'); // tslint:disable-line:no-require-imports
import {Predicate, Context} from './predicate'; import {Predicate, Context} from './predicate';
import hasItems from '../utils/has-items'; import hasItems from '../utils/has-items';
import ofType from '../utils/of-type'; import ofType from '../utils/of-type';

2
source/test/undefined.ts

@ -2,7 +2,7 @@ import test from 'ava';
import m from '..'; import m from '..';
test('undefined', t => { test('undefined', t => {
let x; // tslint:disable-line:prefer-const const x = undefined;
const y = 12; const y = 12;
t.notThrows(() => m(undefined, m.undefined)); t.notThrows(() => m(undefined, m.undefined));

2
tsconfig.json

@ -11,7 +11,7 @@
"pretty": true, "pretty": true,
"newLine": "lf", "newLine": "lf",
"stripInternal": true, "stripInternal": true,
"noImplicitAny": false, "noImplicitAny": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noImplicitThis": true, "noImplicitThis": true,
"noUnusedLocals": true, "noUnusedLocals": true,

Loading…
Cancel
Save