Browse Source

Add more generics, remove `any` where unnecessary (#68)

iss58
Lukas Tetzlaff 7 years ago
committed by Sindre Sorhus
parent
commit
09b955c1c3
  1. 8
      source/lib/operators/not.ts
  2. 16
      source/lib/predicates/array.ts
  3. 2
      source/lib/predicates/boolean.ts
  4. 2
      source/lib/predicates/date.ts
  5. 2
      source/lib/predicates/error.ts
  6. 18
      source/lib/predicates/map.ts
  7. 2
      source/lib/predicates/number.ts
  8. 2
      source/lib/predicates/object.ts
  9. 6
      source/lib/predicates/predicate.ts
  10. 12
      source/lib/predicates/set.ts
  11. 2
      source/lib/predicates/string.ts
  12. 8
      source/lib/predicates/weak-map.ts
  13. 8
      source/lib/predicates/weak-set.ts
  14. 4
      source/lib/utils/has-items.ts
  15. 2
      source/lib/utils/of-type.ts
  16. 22
      source/test/array.ts
  17. 8
      source/test/boolean.ts
  18. 2
      source/test/null-or-undefined.ts
  19. 4
      source/test/null.ts
  20. 2
      source/test/test.ts
  21. 6
      source/test/undefined.ts
  22. 6
      source/test/weak-map.ts
  23. 6
      source/test/weak-set.ts
  24. 7
      tsconfig.json

8
source/lib/operators/not.ts

@ -6,15 +6,15 @@ import {Predicate, validatorSymbol} from '../predicates/predicate';
* @hidden
* @param predictate Predicate to wrap inside the operator.
*/
export const not = <T extends Predicate>(predicate: T) => {
export const not = <T, P extends Predicate<T>>(predicate: P) => {
predicate.addValidator = validator => {
const fn = validator.validator;
const message = validator.message;
validator.message = (x: any) => `[NOT] ${message(x)}`;
validator.validator = (x: any) => !fn(x);
validator.message = (x: T) => `[NOT] ${message(x)}`;
validator.validator = (x: T) => !fn(x);
(predicate as any)[validatorSymbol].push(validator);
predicate[validatorSymbol].push(validator);
return predicate;
};

16
source/lib/predicates/array.ts

@ -2,11 +2,11 @@ import isEqual = require('lodash.isequal'); // tslint:disable-line:no-require-im
import ow from '../..';
import {Predicate, Context} from './predicate';
export class ArrayPredicate extends Predicate<any[]> {
export class ArrayPredicate<T = any> extends Predicate<T[]> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<T[]>) {
super('array', context);
}
@ -51,7 +51,7 @@ export class ArrayPredicate extends Predicate<any[]> {
*
* @param searchElement The value that should be the start of the array.
*/
startsWith(searchElement: any) {
startsWith(searchElement: T) {
return this.addValidator({
message: value => `Expected array to start with \`${searchElement}\`, got \`${value[0]}\``,
validator: value => value[0] === searchElement
@ -63,7 +63,7 @@ export class ArrayPredicate extends Predicate<any[]> {
*
* @param searchElement The value that should be the end of the array.
*/
endsWith(searchElement: any) {
endsWith(searchElement: T) {
return this.addValidator({
message: value => `Expected array to end with \`${searchElement}\`, got \`${value[value.length - 1]}\``,
validator: value => value[value.length - 1] === searchElement
@ -75,7 +75,7 @@ export class ArrayPredicate extends Predicate<any[]> {
*
* @param searchElements The values that should be included in the array.
*/
includes(...searchElements: any[]) {
includes(...searchElements: T[]) {
return this.addValidator({
message: value => `Expected array to include all elements of \`${JSON.stringify(searchElements)}\`, got \`${JSON.stringify(value)}\``,
validator: value => searchElements.every(el => value.indexOf(el) !== -1)
@ -87,7 +87,7 @@ export class ArrayPredicate extends Predicate<any[]> {
*
* @param searchElements The values that should be included in the array.
*/
includesAny(...searchElements: any[]) {
includesAny(...searchElements: T[]) {
return this.addValidator({
message: value => `Expected array to include any element of \`${JSON.stringify(searchElements)}\`, got \`${JSON.stringify(value)}\``,
validator: value => searchElements.some(el => value.indexOf(el) !== -1)
@ -119,7 +119,7 @@ export class ArrayPredicate extends Predicate<any[]> {
*
* @param expected Expected value to match.
*/
deepEqual(expected: any[]) {
deepEqual(expected: T[]) {
return this.addValidator({
message: value => `Expected array to be deeply equal to \`${JSON.stringify(expected)}\`, got \`${JSON.stringify(value)}\``,
validator: value => isEqual(value, expected)
@ -131,7 +131,7 @@ export class ArrayPredicate extends Predicate<any[]> {
*
* @param predicate The predicate that should be applied against every individual item.
*/
ofType<T>(predicate: Predicate<T>) {
ofType(predicate: Predicate<T>) {
let error: string;
return this.addValidator({

2
source/lib/predicates/boolean.ts

@ -4,7 +4,7 @@ export class BooleanPredicate extends Predicate<boolean> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<boolean>) {
super('boolean', context);
}

2
source/lib/predicates/date.ts

@ -4,7 +4,7 @@ export class DatePredicate extends Predicate<Date> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<Date>) {
super('date', context);
}

2
source/lib/predicates/error.ts

@ -4,7 +4,7 @@ export class ErrorPredicate extends Predicate<Error> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<Error>) {
super('error', context);
}

18
source/lib/predicates/map.ts

@ -3,11 +3,11 @@ import {Predicate, Context} from './predicate';
import hasItems from '../utils/has-items';
import ofType from '../utils/of-type';
export class MapPredicate extends Predicate<Map<any, any>> {
export class MapPredicate<T1 = any, T2 = any> extends Predicate<Map<T1, T2>> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<Map<T1, T2>>) {
super('map', context);
}
@ -52,7 +52,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param keys The keys that should be a key in the Map.
*/
hasKeys(...keys: any[]) {
hasKeys(...keys: T1[]) {
return this.addValidator({
message: (_, missingKeys) => `Expected Map to have keys \`${JSON.stringify(missingKeys)}\``,
validator: map => hasItems(map, keys)
@ -64,7 +64,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param keys The keys that could be a key in the Map.
*/
hasAnyKeys(...keys: any[]) {
hasAnyKeys(...keys: T1[]) {
return this.addValidator({
message: () => `Expected Map to have any key of \`${JSON.stringify(keys)}\``,
validator: map => keys.some(key => map.has(key))
@ -76,7 +76,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param values The values that should be a value in the Map.
*/
hasValues(...values: any[]) {
hasValues(...values: T2[]) {
return this.addValidator({
message: (_, missingValues) => `Expected Map to have values \`${JSON.stringify(missingValues)}\``,
validator: map => hasItems(new Set(map.values()), values)
@ -88,7 +88,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param values The values that could be a value in the Map.
*/
hasAnyValues(...values: any[]) {
hasAnyValues(...values: T2[]) {
return this.addValidator({
message: () => `Expected Map to have any value of \`${JSON.stringify(values)}\``,
validator: map => {
@ -104,7 +104,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param predicate The predicate that should be applied against every key in the Map.
*/
keysOfType<T>(predicate: Predicate<T>) {
keysOfType(predicate: Predicate<T1>) {
return this.addValidator({
message: (_, error) => error,
validator: map => ofType(map.keys(), predicate)
@ -116,7 +116,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param predicate The predicate that should be applied against every value in the Map.
*/
valuesOfType<T>(predicate: Predicate<T>) {
valuesOfType(predicate: Predicate<T2>) {
return this.addValidator({
message: (_, error) => error,
validator: map => ofType(map.values(), predicate)
@ -148,7 +148,7 @@ export class MapPredicate extends Predicate<Map<any, any>> {
*
* @param expected Expected Map to match.
*/
deepEqual(expected: Map<any, any>) {
deepEqual(expected: Map<T1, T2>) {
return this.addValidator({
message: map => `Expected Map to be deeply equal to \`${JSON.stringify(Array.from(expected))}\`, got \`${JSON.stringify(Array.from(map))}\``,
validator: map => isEqual(map, expected)

2
source/lib/predicates/number.ts

@ -5,7 +5,7 @@ export class NumberPredicate extends Predicate<number> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<number>) {
super('number', context);
}

2
source/lib/predicates/object.ts

@ -10,7 +10,7 @@ export class ObjectPredicate extends Predicate<object> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<object>) {
super('object', context);
}

6
source/lib/predicates/predicate.ts

@ -15,8 +15,8 @@ export interface Validator<T> {
/**
* @hidden
*/
export interface Context {
validators: Validator<any>[];
export interface Context<T> {
validators: Validator<T>[];
}
/**
@ -30,7 +30,7 @@ export const validatorSymbol = Symbol('validators');
export class Predicate<T = any> implements BasePredicate<T> {
constructor(
type: string,
private readonly context: Context = {
private readonly context: Context<T> = {
validators: []
}
) {

12
source/lib/predicates/set.ts

@ -3,11 +3,11 @@ import {Predicate, Context} from './predicate';
import hasItems from '../utils/has-items';
import ofType from '../utils/of-type';
export class SetPredicate extends Predicate<Set<any>> {
export class SetPredicate<T = any> extends Predicate<Set<T>> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<Set<T>>) {
super('set', context);
}
@ -52,7 +52,7 @@ export class SetPredicate extends Predicate<Set<any>> {
*
* @param items The items that should be a item in the Set.
*/
has(...items: any[]) {
has(...items: T[]) {
return this.addValidator({
message: (_, missingItems) => `Expected Set to have items \`${JSON.stringify(missingItems)}\``,
validator: set => hasItems(set, items)
@ -64,7 +64,7 @@ export class SetPredicate extends Predicate<Set<any>> {
*
* @param items The items that could be a item in the Set.
*/
hasAny(...items: any[]) {
hasAny(...items: T[]) {
return this.addValidator({
message: () => `Expected Set to have any item of \`${JSON.stringify(items)}\``,
validator: set => items.some(item => set.has(item))
@ -76,7 +76,7 @@ export class SetPredicate extends Predicate<Set<any>> {
*
* @param predicate The predicate that should be applied against every item in the Set.
*/
ofType<T>(predicate: Predicate<T>) {
ofType(predicate: Predicate<T>) {
return this.addValidator({
message: (_, error) => error,
validator: set => ofType(set, predicate)
@ -108,7 +108,7 @@ export class SetPredicate extends Predicate<Set<any>> {
*
* @param expected Expected Set to match.
*/
deepEqual(expected: Set<any>) {
deepEqual(expected: Set<T>) {
return this.addValidator({
message: set => `Expected Set to be deeply equal to \`${JSON.stringify(Array.from(expected))}\`, got \`${JSON.stringify(Array.from(set))}\``,
validator: set => isEqual(set, expected)

2
source/lib/predicates/string.ts

@ -5,7 +5,7 @@ export class StringPredicate extends Predicate<string> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<string>) {
super('string', context);
}

8
source/lib/predicates/weak-map.ts

@ -1,11 +1,11 @@
import {Predicate, Context} from './predicate';
import hasItems from '../utils/has-items';
export class WeakMapPredicate extends Predicate<WeakMap<any, any>> {
export class WeakMapPredicate<T1 extends object = any, T2 = any> extends Predicate<WeakMap<T1, T2>> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<WeakMap<T1, T2>>) {
super('weakMap', context);
}
@ -14,7 +14,7 @@ export class WeakMapPredicate extends Predicate<WeakMap<any, any>> {
*
* @param keys The keys that should be a key in the WeakMap.
*/
hasKeys(...keys: any[]) {
hasKeys(...keys: T1[]) {
return this.addValidator({
message: (_, missingKeys) => `Expected WeakMap to have keys \`${JSON.stringify(missingKeys)}\``,
validator: map => hasItems(map, keys)
@ -26,7 +26,7 @@ export class WeakMapPredicate extends Predicate<WeakMap<any, any>> {
*
* @param keys The keys that could be a key in the WeakMap.
*/
hasAnyKeys(...keys: any[]) {
hasAnyKeys(...keys: T1[]) {
return this.addValidator({
message: () => `Expected WeakMap to have any key of \`${JSON.stringify(keys)}\``,
validator: map => keys.some(key => map.has(key))

8
source/lib/predicates/weak-set.ts

@ -1,11 +1,11 @@
import {Predicate, Context} from './predicate';
import hasItems from '../utils/has-items';
export class WeakSetPredicate extends Predicate<WeakSet<any>> {
export class WeakSetPredicate<T extends object = any> extends Predicate<WeakSet<T>> {
/**
* @hidden
*/
constructor(context?: Context) {
constructor(context?: Context<WeakSet<T>>) {
super('weakSet', context);
}
@ -14,7 +14,7 @@ export class WeakSetPredicate extends Predicate<WeakSet<any>> {
*
* @param items The items that should be a item in the WeakSet.
*/
has(...items: any[]) {
has(...items: T[]) {
return this.addValidator({
message: (_, missingItems) => `Expected WeakSet to have items \`${JSON.stringify(missingItems)}\``,
validator: set => hasItems(set, items)
@ -26,7 +26,7 @@ export class WeakSetPredicate extends Predicate<WeakSet<any>> {
*
* @param items The items that could be a item in the WeakSet.
*/
hasAny(...items: any[]) {
hasAny(...items: T[]) {
return this.addValidator({
message: () => `Expected WeakSet to have any item of \`${JSON.stringify(items)}\``,
validator: set => items.some(item => set.has(item))

4
source/lib/utils/has-items.ts

@ -13,8 +13,8 @@ export interface CollectionLike<T> {
* @param items Items to search for.
* @param maxValues Maximum number of values after the search process is stopped. (Default: 5)
*/
export default (source: CollectionLike<any>, items: any[], maxValues = 5) => {
const missingValues: any[] = [];
export default <T>(source: CollectionLike<T>, items: T[], maxValues = 5) => {
const missingValues: T[] = [];
for (const value of items) {
if (source.has(value)) {

2
source/lib/utils/of-type.ts

@ -8,7 +8,7 @@ import {Predicate} from '../predicates/predicate';
* @param source Source collection to test.
* @param predicate Predicate to test every item in the source collection against.
*/
export default (source: IterableIterator<any> | Set<any> | any[], predicate: Predicate): boolean | string => {
export default <T>(source: IterableIterator<T> | Set<T> | T[], predicate: Predicate<T>): boolean | string => {
try {
for (const item of source) {
ow(item, predicate);

22
source/test/array.ts

@ -9,61 +9,61 @@ test('array', t => {
test('array.length', t => {
t.notThrows(() => m(['foo'], m.array.length(1)));
t.notThrows(() => m(['foo', 'bar'], m.array.length(2)));
t.throws(() => m(['foo'] as any, m.array.length(2)), 'Expected array to have length `2`, got `1`');
t.throws(() => m(['foo'], m.array.length(2)), 'Expected array to have length `2`, got `1`');
});
test('array.minLength', t => {
t.notThrows(() => m(['foo'], m.array.minLength(1)));
t.notThrows(() => m(['foo', 'bar'], m.array.minLength(1)));
t.throws(() => m(['foo'] as any, m.array.minLength(2)), 'Expected array to have a minimum length of `2`, got `1`');
t.throws(() => m(['foo'], m.array.minLength(2)), 'Expected array to have a minimum length of `2`, got `1`');
});
test('array.maxLength', t => {
t.notThrows(() => m(['foo'], m.array.maxLength(1)));
t.notThrows(() => m(['foo', 'bar'], m.array.maxLength(4)));
t.throws(() => m(['foo' as any, 'bar'], m.array.maxLength(1)), 'Expected array to have a maximum length of `1`, got `2`');
t.throws(() => m(['foo', 'bar'], m.array.maxLength(1)), 'Expected array to have a maximum length of `1`, got `2`');
});
test('array.startsWith', t => {
t.notThrows(() => m(['foo', 'bar'], m.array.startsWith('foo')));
t.throws(() => m(['foo' as any, 'bar'], m.array.startsWith('bar')), 'Expected array to start with `bar`, got `foo`');
t.throws(() => m(['foo', 'bar'], m.array.startsWith('bar')), 'Expected array to start with `bar`, got `foo`');
});
test('array.endsWith', t => {
t.notThrows(() => m(['foo', 'bar'], m.array.endsWith('bar')));
t.throws(() => m(['foo' as any, 'bar'], m.array.endsWith('foo')), 'Expected array to end with `foo`, got `bar`');
t.throws(() => m(['foo', 'bar'], m.array.endsWith('foo')), 'Expected array to end with `foo`, got `bar`');
});
test('array.includes', t => {
t.notThrows(() => m(['foo', 'bar'], m.array.includes('foo')));
t.notThrows(() => m(['foo', 'bar', 'unicorn'], m.array.includes('foo', 'bar')));
t.throws(() => m(['foo' as any, 'bar'], m.array.includes('foo', 'unicorn')), 'Expected array to include all elements of `["foo","unicorn"]`, got `["foo","bar"]`');
t.throws(() => m(['foo', 'bar'], m.array.includes('foo', 'unicorn')), 'Expected array to include all elements of `["foo","unicorn"]`, got `["foo","bar"]`');
});
test('array.includesAny', t => {
t.notThrows(() => m(['foo', 'bar'], m.array.includesAny('foo')));
t.notThrows(() => m(['foo', 'bar', 'unicorn'], m.array.includesAny('unicorn', 'rainbow')));
t.throws(() => m(['foo' as any, 'bar'], m.array.includesAny('unicorn')), 'Expected array to include any element of `["unicorn"]`, got `["foo","bar"]`');
t.throws(() => m(['foo', 'bar'], m.array.includesAny('unicorn')), 'Expected array to include any element of `["unicorn"]`, got `["foo","bar"]`');
});
test('array.empty', t => {
t.notThrows(() => m([], m.array.empty));
t.throws(() => m(['foo'] as any, m.array.empty), 'Expected array to be empty, got `["foo"]`');
t.throws(() => m(['foo'], m.array.empty), 'Expected array to be empty, got `["foo"]`');
});
test('array.nonEmpty', t => {
t.notThrows(() => m(['foo'], m.array.nonEmpty));
t.throws(() => m([] as any, m.array.nonEmpty), 'Expected array to not be empty');
t.throws(() => m([], m.array.nonEmpty), 'Expected array to not be empty');
});
test('array.deepEqual', t => {
t.notThrows(() => m(['foo'], m.array.deepEqual(['foo'])));
t.notThrows(() => m(['foo', {id: 1}], m.array.deepEqual(['foo', {id: 1}])));
t.throws(() => m(['foo' as any, {id: 1}], m.array.deepEqual(['foo', {id: 2}])), 'Expected array to be deeply equal to `["foo",{"id":2}]`, got `["foo",{"id":1}]`');
t.throws(() => m(['foo', {id: 1}], m.array.deepEqual(['foo', {id: 2}])), 'Expected array to be deeply equal to `["foo",{"id":2}]`, got `["foo",{"id":1}]`');
});
test('array.ofType', t => {
t.notThrows(() => m(['foo', 'bar'], m.array.ofType(m.string)));
t.notThrows(() => m(['foo', 'bar'], m.array.ofType(m.string.minLength(3))));
t.throws(() => m(['foo' as any, 'b'], m.array.ofType(m.string.minLength(3))), 'Expected string to have a minimum length of `3`, got `b`');
t.throws(() => m(['foo', 'b'], m.array.ofType(m.string.minLength(3))), 'Expected string to have a minimum length of `3`, got `b`');
});

8
source/test/boolean.ts

@ -10,14 +10,14 @@ test('boolean.true', t => {
t.notThrows(() => m(true, m.boolean.true));
t.notThrows(() => m(Boolean(true), m.boolean.true));
t.notThrows(() => m(Boolean(1), m.boolean.true));
t.throws(() => m(false as any, m.boolean.true), 'Expected false to be true');
t.throws(() => m(Boolean(0) as any, m.boolean.true), 'Expected false to be true');
t.throws(() => m(false, m.boolean.true), 'Expected false to be true');
t.throws(() => m(Boolean(0), m.boolean.true), 'Expected false to be true');
});
test('boolean.false', t => {
t.notThrows(() => m(false, m.boolean.false));
t.notThrows(() => m(Boolean(false), m.boolean.false));
t.notThrows(() => m(Boolean(0), m.boolean.false));
t.throws(() => m(true as any, m.boolean.false), 'Expected true to be false');
t.throws(() => m(Boolean(1) as any, m.boolean.false), 'Expected true to be false');
t.throws(() => m(true, m.boolean.false), 'Expected true to be false');
t.throws(() => m(Boolean(1), m.boolean.false), 'Expected true to be false');
});

2
source/test/null-or-undefined.ts

@ -9,5 +9,5 @@ test('nullOrUndefined', t => {
t.notThrows(() => m(undefined, m.nullOrUndefined));
t.notThrows(() => m(x, m.nullOrUndefined));
t.notThrows(() => m(y, m.nullOrUndefined));
t.throws(() => m('foo' as any, m.nullOrUndefined), 'Expected argument to be of type `nullOrUndefined` but received type `string`');
t.throws(() => m('foo', m.nullOrUndefined), 'Expected argument to be of type `nullOrUndefined` but received type `string`');
});

4
source/test/null.ts

@ -6,6 +6,6 @@ test('null', t => {
t.notThrows(() => m(null, m.null));
t.notThrows(() => m(x, m.null));
t.throws(() => m(undefined as any, m.null), 'Expected argument to be of type `null` but received type `undefined`');
t.throws(() => m('foo' as any, m.null), 'Expected argument to be of type `null` but received type `string`');
t.throws(() => m(undefined, m.null), 'Expected argument to be of type `null` but received type `undefined`');
t.throws(() => m('foo', m.null), 'Expected argument to be of type `null` but received type `string`');
});

2
source/test/test.ts

@ -5,7 +5,7 @@ test('not', t => {
t.notThrows(() => m(1, m.number.not.infinite));
t.notThrows(() => m(1, m.number.not.infinite.greaterThan(5)));
t.notThrows(() => m('foo!', m.string.not.alphanumeric));
t.throws(() => m('' as any, m.string.not.empty), '[NOT] Expected string to be empty, got ``');
t.throws(() => m('', m.string.not.empty), '[NOT] Expected string to be empty, got ``');
});
test('is', t => {

6
source/test/undefined.ts

@ -7,7 +7,7 @@ test('undefined', t => {
t.notThrows(() => m(undefined, m.undefined));
t.notThrows(() => m(x, m.undefined));
t.throws(() => m(y as any, m.undefined), 'Expected argument to be of type `undefined` but received type `number`');
t.throws(() => m(null as any, m.undefined), 'Expected argument to be of type `undefined` but received type `null`');
t.throws(() => m('foo' as any, m.undefined), 'Expected argument to be of type `undefined` but received type `string`');
t.throws(() => m(y, m.undefined), 'Expected argument to be of type `undefined` but received type `number`');
t.throws(() => m(null, m.undefined), 'Expected argument to be of type `undefined` but received type `null`');
t.throws(() => m('foo', m.undefined), 'Expected argument to be of type `undefined` but received type `string`');
});

6
source/test/weak-map.ts

@ -9,7 +9,7 @@ test('weakMap', t => {
test('weakMap.hasKeys', t => {
const unicorn: any = {unicorn: true};
const rainbow: any = {rainbow: true};
const rainbow = {rainbow: true};
const keys = [{x: 1}, {x: 2}, {x: 3}, {x: 4}, {x: 5}, {x: 6}, {x: 7}, {x: 8}, {x: 9}, {x: 10}];
t.notThrows(() => m(new WeakMap([[unicorn, '🦄']]), m.weakMap.hasKeys(unicorn)));
@ -20,8 +20,8 @@ test('weakMap.hasKeys', t => {
test('weakMap.hasAnyKeys', t => {
const unicorn: any = {unicorn: true};
const rainbow: any = {rainbow: true};
const rocket: any = {rocket: true};
const rainbow = {rainbow: true};
const rocket = {rocket: true};
t.notThrows(() => m(new WeakMap([[unicorn, '🦄']]), m.weakMap.hasAnyKeys(unicorn, rainbow)));
t.notThrows(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(unicorn)));

6
source/test/weak-set.ts

@ -1,9 +1,9 @@
import test from 'ava';
import m from '..';
const unicorn: any = {unicorn: '🦄'};
const rainbow: any = {rainbow: '🌈'};
const rocket: any = {rocket: '🚀'};
const unicorn = {unicorn: '🦄'};
const rainbow = {rainbow: '🌈'};
const rocket = {rocket: '🚀'};
test('weakSet', t => {
t.notThrows(() => m(new WeakSet(), m.weakSet));

7
tsconfig.json

@ -13,16 +13,11 @@
"pretty": true,
"newLine": "lf",
"stripInternal": true,
"noImplicitAny": true,
"strict": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"alwaysStrict": true,
"esModuleInterop": true
},
"exclude": [

Loading…
Cancel
Save