diff --git a/.gitignore b/.gitignore index 46a7572..b2b54e8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ prop-types.js yarn.lock shrinkwrap.yaml coverage.lcov -/remove.js \ No newline at end of file +/remove.js +types/*.js \ No newline at end of file diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..f6c0e8d --- /dev/null +++ b/jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + testMatch: ['/test/*.spec.js'] +} \ No newline at end of file diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..75d2ecb --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,8 @@ +{ + "include": ["src"], + "exclude": ["node_modules"], + "compilerOptions": { + "resolveJsonModule": true, + "lib": ["esnext"] + } +} diff --git a/package.json b/package.json index a8157a4..d138c8f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "remove.js" ], "scripts": { - "test": "jest", + "test": "npm run test:unit && npm run test:types", + "test:unit": "jest", + "test:types": "tsc types/index.spec.ts", "pre:build": "rm -rf dist/", ":build": "rollup -c --environment BUILD:production", "prepublishOnly": "npm run :build", @@ -40,12 +42,12 @@ "@babel/core": "^7.2.2", "@babel/preset-env": "^7.2.3", "babel-core": "^7.0.0-bridge.0", - "babel-jest": "^23.6.0", - "jest": "^23.6.0", - "regenerator-runtime": "^0.13.1", + "babel-jest": "^24.1.0", + "jest": "^24.1.0", "rollup": "^1.1.0", "rollup-plugin-babel": "^4.3.1", - "standard-version": "^4.4.0" + "standard-version": "^4.4.0", + "typescript": "^3.3.3" }, "dependencies": { "vue": "2.*" diff --git a/types/index.d.ts b/types/index.d.ts index 96c694d..3baa43a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -36,9 +36,9 @@ export interface PropTypes { arrayOf(type: ValidatorFn): PropValidator> oneOf(...args: T[]): PropValidator - oneOf(arg1: T1): PropValidator - oneOf(arg1: T1, arg2: T2): PropValidator - oneOf(arg1: T1, arg2: T2, arg3: T3): PropValidator + oneOf(arg1: T1): PropValidator + oneOf(arg1: T1, arg2: T2): PropValidator + oneOf(arg1: T1, arg2: T2, arg3: T3): PropValidator oneOf(arg1: T1, arg2: T2, arg3: T3, arg4: T4): PropValidator oneOf(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): PropValidator oneOf(arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6): PropValidator @@ -89,20 +89,20 @@ export interface PropTypesChain< T, U = T extends string ? string - : T extends StringConstructor + : T extends String ? string : T extends number ? number - : T extends NumberConstructor + : T extends Number ? number : T extends boolean ? boolean - : T extends BooleanConstructor + : T extends Boolean ? boolean + : T extends symbol + ? symbol : T extends Symbol - ? Symbol - : T extends SymbolConstructor - ? Symbol + ? symbol : (() => T) > { isRequired: PropOptions diff --git a/types/index.spec.ts b/types/index.spec.ts index 3c89281..159bdb9 100644 --- a/types/index.spec.ts +++ b/types/index.spec.ts @@ -9,7 +9,6 @@ const props = { string: PropTypes.string.value('foo').validate(value => 'foo' == value).isRequired, number: PropTypes.number.value(1).validate(value => 1 == value).isRequired, boolean: PropTypes.bool.value(true).validate(value => value).isRequired, - symbol: PropTypes.symbol.value(Symbol('1')).validate(value => !!value).isRequired, array: PropTypes.array.value(() => []).validate(value => 1 === value.length).isRequired, object: PropTypes.object.value(() => ({})).validate(value => 'foo' in value).isRequired, func: PropTypes.func.value(() => (a: string) => null).validate(value => value()).isRequired, @@ -24,7 +23,7 @@ const props = { date: PropTypes.instanceOf(Date).value(() => new Date()).validate(value => value.getTime() > 0).isRequired, foo: PropTypes.instanceOf(Foo).value(() => new Foo()).validate(value => value.isValid).isRequired, - String: PropTypes.instanceOf(String).value(() => new String()).validate(value => value.at(0) > 'a').isRequired, + String: PropTypes.instanceOf(String).value(String('str')).validate(value => value.charAt(0) > 'a').isRequired, shape: PropTypes.shape({ foo: PropTypes.bool, @@ -34,7 +33,6 @@ const props = { objectOfNumber: PropTypes.objectOf(PropTypes.number).value(() => ({ foo: 1, bar: 2 })).validate(value => value.foo > 0).isRequired, objectOfString: PropTypes.objectOf(Number), - objectOfSymbol: PropTypes.objectOf(Symbol), objectOfValidatorInferredType: PropTypes.objectOf((value: { foo: boolean}) => value.foo).value(() => ({ one: { foo: true } })), }