Skip to content

Commit

Permalink
conf: add type declarations for all modules (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 22, 2020
1 parent f7d5d5b commit 7526d15
Show file tree
Hide file tree
Showing 12 changed files with 705 additions and 202 deletions.
3 changes: 2 additions & 1 deletion config/builds/vest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const PLUGINS = [
LIBRARY_NAME: JSON.stringify(PACKAGE_VEST),
}),
compiler(),
terser(),
];

const buildConfig = ({ format = DEFAULT_FORMAT, min = false } = {}) => ({
Expand All @@ -45,7 +46,7 @@ const buildConfig = ({ format = DEFAULT_FORMAT, min = false } = {}) => ({
format,
name: PACKAGE_VEST,
},
plugins: min ? [...PLUGINS, terser()] : PLUGINS,
plugins: PLUGINS,
});

export default [buildConfig(), buildConfig({ min: true })];
3 changes: 3 additions & 0 deletions packages/vest/any.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function any(...args: any[]): boolean;

export default any;
12 changes: 12 additions & 0 deletions packages/vest/classNames.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare function classNames(
res: Partial<IVestResult>,
classes?: {
valid?: string;
tested?: string;
invalid?: string;
warning?: string;
untested?: string;
}
): (fieldName: string) => string;

export default classNames;
19 changes: 19 additions & 0 deletions packages/vest/enforceExtended.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface ExtendedRules {
isAlphanumeric: (...args: any) => IEnforceRules;
isCreditCard: (...args: any) => IEnforceRules;
isCurrency: (...args: any) => IEnforceRules;
isEmail: (...args: any) => IEnforceRules;
isIP: (...args: any) => IEnforceRules;
isIdentityCard: (...args: any) => IEnforceRules;
isJSON: (...args: any) => IEnforceRules;
isLocale: (...args: any) => IEnforceRules;
isMimeType: (...args: any) => IEnforceRules;
isMobilePhone: (...args: any) => IEnforceRules;
isPassportNumber: (...args: any) => IEnforceRules;
isPostalCode: (...args: any) => IEnforceRules;
isURL: (...args: any) => IEnforceRules;
}

declare function enforceExtended(value: any): EnforceExtendMap<ExtendedRules>;

export default enforceExtended;
2 changes: 1 addition & 1 deletion packages/vest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vest",
"version": "2.0.0",
"description": "Validation Test",
"main": "./vest.min.js",
"main": "./vest.js",
"types": "./vest.d.ts",
"author": "ealush",
"license": "MIT",
Expand Down
13 changes: 11 additions & 2 deletions packages/vest/src/spec/infra.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { execSync } = require('child_process');
const glob = require('glob');
const vest = require('..');
const packagePath = require('../../../../util/packagePath');
const { version } = require('../../package.json');
Expand Down Expand Up @@ -130,9 +131,17 @@ describe('General scenario tests', () => {
});

describe('TypeScript Typings', () => {
it('Should Pass tsc validation on a valid file', () => {
const declarationFiles = glob
.sync('src/**/*.d.ts', {
cwd: packagePath('vest'),
absolute: true,
ignore: '**/spec/*',
})
.join(' ');

it(`Should pass tsc validation`, () => {
expect(() => {
execSync(`node_modules/.bin/tsc ${packagePath('vest', 'vest.d.ts')}`);
execSync(`node_modules/.bin/tsc ${declarationFiles}`);
}).not.toThrow();
});

Expand Down
3 changes: 3 additions & 0 deletions packages/vest/src/utilities/any.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function any(...args: any[]): boolean;

export default any;
12 changes: 12 additions & 0 deletions packages/vest/src/utilities/classNames.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare function classNames(
res: Partial<IVestResult>,
classes?: {
valid?: string;
tested?: string;
invalid?: string;
warning?: string;
untested?: string;
}
): (fieldName: string) => string;

export default classNames;
19 changes: 19 additions & 0 deletions packages/vest/src/utilities/enforceExtended.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface ExtendedRules {
isAlphanumeric: (...args: any) => IEnforceRules;
isCreditCard: (...args: any) => IEnforceRules;
isCurrency: (...args: any) => IEnforceRules;
isEmail: (...args: any) => IEnforceRules;
isIP: (...args: any) => IEnforceRules;
isIdentityCard: (...args: any) => IEnforceRules;
isJSON: (...args: any) => IEnforceRules;
isLocale: (...args: any) => IEnforceRules;
isMimeType: (...args: any) => IEnforceRules;
isMobilePhone: (...args: any) => IEnforceRules;
isPassportNumber: (...args: any) => IEnforceRules;
isPostalCode: (...args: any) => IEnforceRules;
isURL: (...args: any) => IEnforceRules;
}

declare function enforceExtended(value: any): EnforceExtendMap<ExtendedRules>;

export default enforceExtended;

0 comments on commit 7526d15

Please sign in to comment.