From d73aabd86011cb0d4dd103f59466934cbd21f4d1 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Mon, 18 Sep 2023 16:01:22 +0200 Subject: [PATCH 1/5] Install Prettier --- .prettierignore | 3 +++ .prettierrc.json | 4 ++++ package-lock.json | 22 ++++++++++++++++++++++ package.json | 5 ++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.json diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..ab670574 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +CHANGELOG.md diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..703dfa5e --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "quoteProps": "consistent" +} diff --git a/package-lock.json b/package-lock.json index 685d3a22..1c59d9dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "jest-extended": "^4.0.1", "jest-runner-tsd": "^6.0.0", "markdownlint-cli": "^0.36.0", + "prettier": "3.0.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2", @@ -5006,6 +5007,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -9813,6 +9829,12 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true + }, "pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index 77e440c7..f5009479 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,11 @@ "test:watch": "jest --watch", "type-test": "jest -c jest.config.tsd.ts", "type-test:watch": "jest -c jest.config.tsd.ts --watch", - "lint": "npm run lint:eslint && npm run lint:markdownlint", + "format": "prettier . --write", + "lint": "npm run lint:eslint && npm run lint:markdownlint && npm run lint:prettier", "lint:eslint": "eslint .", "lint:markdownlint": "markdownlint \"**/*.md\"", + "lint:prettier": "prettier . --check", "build": "tsc --project tsconfig.build.json" }, "repository": { @@ -54,6 +56,7 @@ "jest-extended": "^4.0.1", "jest-runner-tsd": "^6.0.0", "markdownlint-cli": "^0.36.0", + "prettier": "3.0.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2", From 4fec9c52e1d669ddd51f780b526d1ff19b257a64 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Mon, 18 Sep 2023 16:03:29 +0200 Subject: [PATCH 2/5] Remove extensive comments from tsconfig --- tsconfig.json | 106 +++++--------------------------------------------- 1 file changed, 9 insertions(+), 97 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index e4eae920..c8ad1020 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,102 +1,14 @@ { "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Projects */ - // "incremental": true, /* Enable incremental compilation */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2019", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ - // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "resolveJsonModule": true, /* Enable importing .json files */ - // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ - - /* Emit */ - "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./dist/", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ - // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ - // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "target": "es2019", + "module": "commonjs", + "moduleResolution": "node", + "declaration": true, + "outDir": "./dist/", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true }, "include": [ ".eslintrc.cjs", From 053a8cc8c48f0338c4ceb6bc76597851c73f9f8c Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Mon, 18 Sep 2023 16:43:49 +0200 Subject: [PATCH 3/5] Make ESLint and Markdownlint configs compatible with Prettier --- .eslintrc.cjs | 86 +++++++++++++++++----------------------------- .markdownlint.yaml | 2 -- package-lock.json | 20 +++++++++++ package.json | 1 + 4 files changed, 52 insertions(+), 57 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 7660c19d..02f8f701 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -10,6 +10,7 @@ module.exports = { 'plugin:@typescript-eslint/strict-type-checked', 'plugin:@typescript-eslint/stylistic-type-checked', 'plugin:unicorn/recommended', + 'prettier', ], parser: '@typescript-eslint/parser', parserOptions: { @@ -21,35 +22,21 @@ module.exports = { rules: { // Core ESLint rules 'accessor-pairs': 'error', - 'array-bracket-spacing': 'error', - 'arrow-parens': ['error', 'as-needed'], - 'arrow-spacing': 'error', - 'block-spacing': 'error', - 'brace-style': ['error', 'stroustrup'], - 'camelcase': ['error', { - allow: ['Vue2_6', 'Vue2_7'], - }], - 'comma-dangle': ['error', 'always-multiline'], - 'comma-spacing': 'error', - 'comma-style': 'error', + 'camelcase': [ + 'error', + { + allow: ['Vue2_6', 'Vue2_7'], + }, + ], 'consistent-return': 'error', 'curly': ['error', 'all'], - 'dot-location': ['error', 'property'], 'dot-notation': 'error', - 'eol-last': 'error', 'eqeqeq': 'error', - 'func-call-spacing': 'error', 'getter-return': 'error', 'grouped-accessor-pairs': ['error', 'getBeforeSet'], 'guard-for-in': 'error', - 'indent': 'off', // replaced by @typescript-eslint/indent - 'key-spacing': 'off', // replaced by @typescript-eslint/key-spacing - 'keyword-spacing': 'error', - 'linebreak-style': ['error', 'unix'], - 'new-parens': 'error', 'no-array-constructor': 'error', 'no-bitwise': 'error', - 'no-confusing-arrow': ['error', { allowParens: true }], 'no-constant-binary-expression': 'error', 'no-constant-condition': 'error', 'no-else-return': ['error', { allowElseIf: false }], @@ -57,72 +44,61 @@ module.exports = { 'no-lonely-if': 'error', 'no-loop-func': 'error', 'no-mixed-operators': 'error', - 'no-multi-spaces': 'error', 'no-new-object': 'error', 'no-prototype-builtins': 'error', 'no-return-assign': 'error', 'no-return-await': 'error', 'no-shadow': 'off', // replaced by @typescript-eslint/no-shadow 'no-template-curly-in-string': 'error', - 'no-trailing-spaces': 'error', - 'no-unsafe-optional-chaining': ['error', { 'disallowArithmeticOperators': true }], - 'object-curly-spacing': 'off', // replaced by @typescript-eslint/object-curly-spacing + 'no-unsafe-optional-chaining': [ + 'error', + { disallowArithmeticOperators: true }, + ], 'object-shorthand': ['error', 'always', { avoidQuotes: true }], 'prefer-arrow-callback': 'error', 'prefer-template': 'error', - 'quotes': ['error', 'single'], + 'quotes': [ + 'error', + 'single', + { avoidEscape: true, allowTemplateLiterals: false }, + ], 'radix': 'error', - 'semi': 'error', - 'space-before-blocks': 'error', - 'space-before-function-paren': ['error', { - anonymous: 'never', - named: 'never', - asyncArrow: 'always', - }], - 'space-in-parens': 'error', - 'space-infix-ops': 'off', // replaced by @typescript-eslint/space-infix-ops 'spaced-comment': 'error', - 'space-unary-ops': 'error', - 'template-curly-spacing': 'error', // eslint-plugin-unicorn 'unicorn/filename-case': 'off', 'unicorn/no-null': 'off', 'unicorn/no-useless-undefined': 'off', // conflicts with consistent-return - 'unicorn/prevent-abbreviations': ['warn', { - replacements: { - prop: false, + 'unicorn/prevent-abbreviations': [ + 'warn', + { + replacements: { + prop: false, + }, }, - }], + ], // @typescript-eslint/eslint-plugin '@typescript-eslint/consistent-type-exports': 'error', '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/explicit-module-boundary-types': 'error', - '@typescript-eslint/indent': ['error', 2], - '@typescript-eslint/key-spacing': 'error', - '@typescript-eslint/member-delimiter-style': 'error', - '@typescript-eslint/no-confusing-void-expression': ['error', { - ignoreVoidOperator: true, - ignoreArrowShorthand: true, - }], + '@typescript-eslint/no-confusing-void-expression': [ + 'error', + { + ignoreVoidOperator: true, + ignoreArrowShorthand: true, + }, + ], '@typescript-eslint/no-explicit-any': 'off', // needed for Vue types compatibility '@typescript-eslint/no-extraneous-class': 'off', '@typescript-eslint/no-shadow': ['warn', { ignoreOnInitialization: true }], - '@typescript-eslint/object-curly-spacing': ['error', 'always'], '@typescript-eslint/prefer-enum-initializers': 'error', '@typescript-eslint/prefer-readonly': 'error', '@typescript-eslint/promise-function-async': 'error', '@typescript-eslint/sort-type-constituents': 'warn', - '@typescript-eslint/space-infix-ops': 'error', '@typescript-eslint/switch-exhaustiveness-check': 'error', - '@typescript-eslint/type-annotation-spacing': 'error', }, - ignorePatterns: [ - '**/*.json', - 'node_modules', - 'dist', - ], + ignorePatterns: ['**/*.json', 'node_modules', 'dist'], overrides: [ { files: ['*.cjs'] }, { diff --git a/.markdownlint.yaml b/.markdownlint.yaml index bdaa37a7..0b02bf7b 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -1,4 +1,2 @@ line-length: false no-inline-html: false -ul-style: - style: sublist diff --git a/package-lock.json b/package-lock.json index 1c59d9dc..5cd3c4e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@typescript-eslint/eslint-plugin": "^6.7.0", "@typescript-eslint/parser": "^6.7.0", "eslint": "^8.49.0", + "eslint-config-prettier": "^9.0.0", "eslint-plugin-jest": "^27.4.0", "eslint-plugin-jest-formatting": "^3.1.0", "eslint-plugin-unicorn": "^48.0.1", @@ -2648,6 +2649,18 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-prettier": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz", + "integrity": "sha512-IcJsTkJae2S35pRsRAwoCE+925rJJStOdkKnLVgtE+tEpqU0EVVM7OqrwxqgptKdX29NUwC82I5pXsGFIgSevw==", + "dev": true, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-plugin-jest": { "version": "27.4.0", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.4.0.tgz", @@ -8120,6 +8133,13 @@ "text-table": "^0.2.0" } }, + "eslint-config-prettier": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz", + "integrity": "sha512-IcJsTkJae2S35pRsRAwoCE+925rJJStOdkKnLVgtE+tEpqU0EVVM7OqrwxqgptKdX29NUwC82I5pXsGFIgSevw==", + "dev": true, + "requires": {} + }, "eslint-plugin-jest": { "version": "27.4.0", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.4.0.tgz", diff --git a/package.json b/package.json index f5009479..604b7ee0 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@typescript-eslint/eslint-plugin": "^6.7.0", "@typescript-eslint/parser": "^6.7.0", "eslint": "^8.49.0", + "eslint-config-prettier": "^9.0.0", "eslint-plugin-jest": "^27.4.0", "eslint-plugin-jest-formatting": "^3.1.0", "eslint-plugin-unicorn": "^48.0.1", From 2be7254526924b926823e3d7739560b116a38b2d Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Mon, 18 Sep 2023 16:49:44 +0200 Subject: [PATCH 4/5] Format files with Prettier --- .github/dependabot.yaml | 24 +- .github/workflows/release.yaml | 6 +- README.md | 346 +++++++++--------- src/prop-types/any.ts | 5 +- src/prop-types/array.ts | 5 +- src/prop-types/boolean.ts | 5 +- src/prop-types/function.ts | 4 +- src/prop-types/instanceOf.ts | 11 +- src/prop-types/integer.ts | 4 +- src/prop-types/number.ts | 4 +- src/prop-types/object.ts | 5 +- src/prop-types/oneOf.ts | 37 +- src/prop-types/oneOfObjectKeys.ts | 7 +- src/prop-types/oneOfTypes.ts | 6 +- src/prop-types/string.ts | 4 +- src/prop-types/symbol.ts | 4 +- src/prop-types/vueComponent.ts | 6 +- src/types.ts | 21 +- src/util.ts | 13 +- src/validators/index.ts | 16 +- src/validators/isInstanceOf.ts | 14 +- src/validators/isInteger.ts | 2 +- src/validators/isNegative.ts | 2 +- src/validators/isNonNegative.ts | 2 +- src/validators/isNonPositive.ts | 2 +- src/validators/isOneOf.ts | 14 +- src/validators/isPositive.ts | 2 +- src/validators/isSymbol.ts | 2 +- tests/prop-types/oneOf.spec.ts | 42 ++- tests/prop-types/oneOfTypes.spec.ts | 16 +- tests/validators/index.spec.ts | 32 +- tests/validators/isInstanceOf.spec.ts | 18 +- tsconfig.json | 5 +- type-tests/prop-types/any.type.spec.ts | 36 +- type-tests/prop-types/array.type.spec.ts | 108 ++++-- type-tests/prop-types/boolean.type.spec.ts | 32 +- type-tests/prop-types/function.type.spec.ts | 78 +++- type-tests/prop-types/instanceOf.type.spec.ts | 72 +++- type-tests/prop-types/integer.type.spec.ts | 16 +- type-tests/prop-types/number.type.spec.ts | 32 +- type-tests/prop-types/object.type.spec.ts | 36 +- type-tests/prop-types/oneOf.type.spec.ts | 52 ++- .../prop-types/oneOfObjectKeys.type.spec.ts | 44 ++- type-tests/prop-types/oneOfTypes.type.spec.ts | 50 ++- type-tests/prop-types/string.type.spec.ts | 56 ++- type-tests/prop-types/symbol.type.spec.ts | 32 +- .../prop-types/vueComponent.type.spec.ts | 80 +++- type-tests/utils.ts | 15 +- 48 files changed, 944 insertions(+), 481 deletions(-) diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index df91b008..363fdb98 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -2,25 +2,25 @@ version: 2 updates: - - package-ecosystem: "npm" - versioning-strategy: "increase" - directory: "/" + - package-ecosystem: 'npm' + versioning-strategy: 'increase' + directory: '/' schedule: - interval: "daily" + interval: 'daily' labels: - - "dependencies" + - 'dependencies' groups: typescript-eslint: patterns: - - "@typescript-eslint/*" + - '@typescript-eslint/*' typescript: patterns: - - "typescript" - - "@tsd/typescript" + - 'typescript' + - '@tsd/typescript' - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: 'github-actions' + directory: '/' schedule: - interval: "daily" + interval: 'daily' labels: - - "dependencies" + - 'dependencies' diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b6b4c8fb..18db98ad 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,9 +9,9 @@ on: default: 'minor' type: choice options: - - major - - minor - - patch + - major + - minor + - patch env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index f1f7f492..9403d60b 100644 --- a/README.md +++ b/README.md @@ -136,10 +136,10 @@ npm install vue-ts-types Each of the prop functions returns an object with the following properties: -* `.optional`: Use this to mark the prop as not required with a default value of `undefined`. Also includes `undefined` in the resulting prop type. -* `.nullable`: Use this to mark the prop as not required with a default value of `null`. Also includes `null` in the resulting prop type. -* `.required`: Use this to mark the prop as required without a default value. -* `.withDefault(value)`: Use this to set a default value for the prop. Note that the value has to fit the prop type. For non-primitive types, the value has to be a function that returns the default value. +- `.optional`: Use this to mark the prop as not required with a default value of `undefined`. Also includes `undefined` in the resulting prop type. +- `.nullable`: Use this to mark the prop as not required with a default value of `null`. Also includes `null` in the resulting prop type. +- `.required`: Use this to mark the prop as required without a default value. +- `.withDefault(value)`: Use this to set a default value for the prop. Note that the value has to fit the prop type. For non-primitive types, the value has to be a function that returns the default value. > ℹ️ **Note:** > Due to the way Vue props work, a prop's default value will only be used when passing `undefined`, not for `null`. @@ -154,23 +154,23 @@ import { numberProp } from 'vue-ts-types'; type Validator = (value: unknown) => string | undefined; -const isPositive: Validator = value => { +const isPositive: Validator = (value) => { if (typeof value !== 'number' || value <= 0 || Number.isNaN(value)) { return 'value should be a positive number'; } return undefined; -} +}; -numberProp(isPositive).optional - // → prop type: number | undefined +numberProp(isPositive).optional; +// → prop type: number | undefined ``` For convenience, some common validator functions are included in the library and can be imported just like prop types: -* `isNegative`: only allows negative numbers (`< 0`) -* `isPositive`: only allows positive numbers (`> 0`) -* `isNonNegative`: only allows non-negative numbers (`>= 0`) -* `isNonPositive`: only allows non-positive numbers (`<= 0`) +- `isNegative`: only allows negative numbers (`< 0`) +- `isPositive`: only allows positive numbers (`> 0`) +- `isNonNegative`: only allows non-negative numbers (`>= 0`) +- `isNonPositive`: only allows non-positive numbers (`<= 0`) ### `stringProp(validator?: Validator)` @@ -178,25 +178,25 @@ Allows any string. No further runtime validation is performed by default. Type parameter `T` can be used to restrict the type at compile time with a union type. (Consider using [`oneOfProp`](#oneofproptallowedvalues-readonly-any-validator-validator) in this case.) ```ts -stringProp().optional - // → prop type: string | undefined -stringProp().nullable - // → prop type: string | null -stringProp().required - // → prop type: string -stringProp().withDefault('foo') - // → prop type: string +stringProp().optional; +// → prop type: string | undefined +stringProp().nullable; +// → prop type: string | null +stringProp().required; +// → prop type: string +stringProp().withDefault('foo'); +// → prop type: string type Foo = 'a' | 'b' | 'c'; -stringProp().optional - // → prop type: Foo | undefined -stringProp().nullable - // → prop type: Foo | null -stringProp().required - // → prop type: Foo -stringProp().withDefault('a') - // → prop type: Foo +stringProp().optional; +// → prop type: Foo | undefined +stringProp().nullable; +// → prop type: Foo | null +stringProp().required; +// → prop type: Foo +stringProp().withDefault('a'); +// → prop type: Foo ``` ### `booleanProp(validator?: Validator)` @@ -204,14 +204,14 @@ stringProp().withDefault('a') Allows any boolean (validated at runtime and compile time). ```ts -booleanProp().optional - // → prop type: boolean | undefined -booleanProp().nullable - // → prop type: boolean | null -booleanProp().required - // → prop type: boolean -booleanProp().withDefault(false) - // → prop type: boolean +booleanProp().optional; +// → prop type: boolean | undefined +booleanProp().nullable; +// → prop type: boolean | null +booleanProp().required; +// → prop type: boolean +booleanProp().withDefault(false); +// → prop type: boolean ``` ### `numberProp(validator?: Validator)` @@ -220,25 +220,25 @@ Allows any number (validated at runtime and compile time). Type parameter `T` can be used to restrict the type at compile time with a union type. (Consider using [`oneOfProp`](#oneofproptallowedvalues-readonly-any-validator-validator) in this case.) ```ts -numberProp().optional - // → prop type: number | undefined -numberProp().nullable - // → prop type: number | null -numberProp().required - // → prop type: number -numberProp().withDefault(3.1415) - // → prop type: number +numberProp().optional; +// → prop type: number | undefined +numberProp().nullable; +// → prop type: number | null +numberProp().required; +// → prop type: number +numberProp().withDefault(3.1415); +// → prop type: number type Foo = 1 | 2 | 3; -numberProp().optional - // → prop type: Foo | undefined -numberProp().nullable - // → prop type: Foo | null -numberProp().required - // → prop type: Foo -numberProp().withDefault(1) - // → prop type: Foo +numberProp().optional; +// → prop type: Foo | undefined +numberProp().nullable; +// → prop type: Foo | null +numberProp().required; +// → prop type: Foo +numberProp().withDefault(1); +// → prop type: Foo ``` ### `integerProp(validator?: Validator)` @@ -246,14 +246,14 @@ numberProp().withDefault(1) Allows any integer (validated at runtime). ```ts -integerProp().optional - // → prop type: number | undefined -integerProp().nullable - // → prop type: number | null -integerProp().required - // → prop type: number -integerProp().withDefault(42) - // → prop type: number +integerProp().optional; +// → prop type: number | undefined +integerProp().nullable; +// → prop type: number | null +integerProp().required; +// → prop type: number +integerProp().withDefault(42); +// → prop type: number ``` ### `symbolProp(validator?: Validator)` @@ -261,14 +261,14 @@ integerProp().withDefault(42) Allows any symbol (validated at runtime and compile time). ```ts -symbolProp().optional - // → prop type: symbol | undefined -symbolProp().nullable - // → prop type: symbol | null -symbolProp().required - // → prop type: symbol -symbolProp().withDefault(Symbol('foo')) - // → prop type: symbol +symbolProp().optional; +// → prop type: symbol | undefined +symbolProp().nullable; +// → prop type: symbol | null +symbolProp().required; +// → prop type: symbol +symbolProp().withDefault(Symbol('foo')); +// → prop type: symbol ``` ### `vueComponentProp(validator?: Validator)` @@ -276,14 +276,14 @@ symbolProp().withDefault(Symbol('foo')) Allows any Vue component instance, name or options object. No built-in runtime validation is performed by default. ```ts -vueComponentProp().optional - // → prop type: VueComponent | undefined -vueComponentProp().nullable - // → prop type: VueComponent | null -vueComponentProp().required - // → prop type: VueComponent -vueComponentProp().withDefault('close-icon') - // → prop type: VueComponent +vueComponentProp().optional; +// → prop type: VueComponent | undefined +vueComponentProp().nullable; +// → prop type: VueComponent | null +vueComponentProp().required; +// → prop type: VueComponent +vueComponentProp().withDefault('close-icon'); +// → prop type: VueComponent ``` > ℹ️ **Note:** @@ -296,23 +296,23 @@ Allows any type. No built-in runtime validation is performed by default. Type parameter `T` can be used to restrict the type at compile time. ```ts -anyProp().optional - // → prop type: any -anyProp().nullable - // → prop type: any -anyProp().required - // → prop type: any -anyProp().withDefault('foo') - // → prop type: any - -anyProp().optional - // → prop type: string | undefined -anyProp().nullable - // → prop type: string | null -anyProp().required - // → prop type: string -anyProp().withDefault('foo') - // → prop type: string +anyProp().optional; +// → prop type: any +anyProp().nullable; +// → prop type: any +anyProp().required; +// → prop type: any +anyProp().withDefault('foo'); +// → prop type: any + +anyProp().optional; +// → prop type: string | undefined +anyProp().nullable; +// → prop type: string | null +anyProp().required; +// → prop type: string +anyProp().withDefault('foo'); +// → prop type: string ``` ### `arrayProp(validator?: Validator)` @@ -321,23 +321,23 @@ Allows any array. No further runtime validation is performed by default. Type parameter `T` can be used to restrict the type of the array items at compile time. ```ts -arrayProp().optional - // → prop type: unknown[] | undefined -arrayProp().nullable - // → prop type: unknown[] | null -arrayProp().required - // → prop type: unknown[] -arrayProp().withDefault(() => []) - // → prop type: unknown[] - -arrayProp().optional - // → prop type: string[] | undefined -arrayProp().nullable - // → prop type: string[] | null -arrayProp().required - // → prop type: string[] -arrayProp().withDefault(() => ['foo', 'bar']) - // → prop type: string[] +arrayProp().optional; +// → prop type: unknown[] | undefined +arrayProp().nullable; +// → prop type: unknown[] | null +arrayProp().required; +// → prop type: unknown[] +arrayProp().withDefault(() => []); +// → prop type: unknown[] + +arrayProp().optional; +// → prop type: string[] | undefined +arrayProp().nullable; +// → prop type: string[] | null +arrayProp().required; +// → prop type: string[] +arrayProp().withDefault(() => ['foo', 'bar']); +// → prop type: string[] ``` ### `objectProp(validator?: Validator)` @@ -346,27 +346,27 @@ Allows any object. No further runtime validation is performed by default. Type parameter `T` can be used to restrict the type at compile time. ```ts -objectProp().optional - // → prop type: object | undefined -objectProp().nullable - // → prop type: object | null -objectProp().required - // → prop type: object -objectProp().withDefault(() => ({})) - // → prop type: object +objectProp().optional; +// → prop type: object | undefined +objectProp().nullable; +// → prop type: object | null +objectProp().required; +// → prop type: object +objectProp().withDefault(() => ({})); +// → prop type: object interface User { name: string; } -objectProp().optional - // → prop type: User | undefined -objectProp().nullable - // → prop type: User | null -objectProp().required - // → prop type: User -objectProp().withDefault(() => ({ name: 'John' })) - // → prop type: User +objectProp().optional; +// → prop type: User | undefined +objectProp().nullable; +// → prop type: User | null +objectProp().required; +// → prop type: User +objectProp().withDefault(() => ({ name: 'John' })); +// → prop type: User ``` ### `functionProp(validator?: Validator)` @@ -378,21 +378,21 @@ Type parameter `T` can be used to restrict the type to a specific function signa > There is no `.withDefault()` function for this prop type. ```ts -functionProp().optional - // → prop type: Function | undefined -functionProp().nullable - // → prop type: Function | null -functionProp().required - // → prop type: Function +functionProp().optional; +// → prop type: Function | undefined +functionProp().nullable; +// → prop type: Function | null +functionProp().required; +// → prop type: Function type MyFunc = (a: number, b: string) => boolean; -functionProp().optional - // → prop type: MyFunc | undefined -functionProp().nullable - // → prop type: MyFunc | null -functionProp().required - // → prop type: MyFunc +functionProp().optional; +// → prop type: MyFunc | undefined +functionProp().nullable; +// → prop type: MyFunc | null +functionProp().required; +// → prop type: MyFunc ``` ### `oneOfProp(allowedValues: readonly any[], validator?: Validator)` @@ -404,14 +404,14 @@ Type parameter `T` can be used to adjust the inferred type at compile time, this > Proper type checking is only possible if the allowed values are readonly, usually through `as const`. ```ts -oneOfProp(['foo', 'bar'] as const).optional - // → prop type: 'foo' | 'bar' | undefined -oneOfProp(['foo', 'bar'] as const).nullable - // → prop type: 'foo' | 'bar' | null -oneOfProp(['foo', 'bar'] as const).required - // → prop type: 'foo' | 'bar' -oneOfProp(['foo', 'bar'] as const).withDefault('foo') - // → prop type: 'foo' | 'bar' +oneOfProp(['foo', 'bar'] as const).optional; +// → prop type: 'foo' | 'bar' | undefined +oneOfProp(['foo', 'bar'] as const).nullable; +// → prop type: 'foo' | 'bar' | null +oneOfProp(['foo', 'bar'] as const).required; +// → prop type: 'foo' | 'bar' +oneOfProp(['foo', 'bar'] as const).withDefault('foo'); +// → prop type: 'foo' | 'bar' ``` ### `oneOfObjectKeysProp(object: object, validator?: Validator)` @@ -420,14 +420,14 @@ Allows any of the keys of the specified object (validated at runtime and compile Type parameter `T` can be used to adjust the inferred type at compile time, this is usually not necessary. ```ts -oneOfObjectKeysProp({ foo: 1, bar: 2 }).optional - // → prop type: 'foo' | 'bar' | undefined -oneOfObjectKeysProp({ foo: 1, bar: 2 }).nullable - // → prop type: 'foo' | 'bar' | null -oneOfObjectKeysProp({ foo: 1, bar: 2 }).required - // → prop type: 'foo' | 'bar' -oneOfObjectKeysProp({ foo: 1, bar: 2 }).withDefault('foo') - // → prop type: 'foo' | 'bar' +oneOfObjectKeysProp({ foo: 1, bar: 2 }).optional; +// → prop type: 'foo' | 'bar' | undefined +oneOfObjectKeysProp({ foo: 1, bar: 2 }).nullable; +// → prop type: 'foo' | 'bar' | null +oneOfObjectKeysProp({ foo: 1, bar: 2 }).required; +// → prop type: 'foo' | 'bar' +oneOfObjectKeysProp({ foo: 1, bar: 2 }).withDefault('foo'); +// → prop type: 'foo' | 'bar' ``` ### `oneOfTypesProp(type: PropType, validator?: Validator)` @@ -436,14 +436,14 @@ Allows any of the passed constructor types (validated at runtime). Type parameter `T` has to be used to adjust the type at compile time. ```ts -oneOfTypesProp([Number, String]).optional - // → prop type: string | number | undefined -oneOfTypesProp([Number, String]).nullable - // → prop type: string | number | null -oneOfTypesProp([Number, String]).required - // → prop type: string | number -oneOfTypesProp([Number, String]).withDefault(42) - // → prop type: string | number +oneOfTypesProp([Number, String]).optional; +// → prop type: string | number | undefined +oneOfTypesProp([Number, String]).nullable; +// → prop type: string | number | null +oneOfTypesProp([Number, String]).required; +// → prop type: string | number +oneOfTypesProp([Number, String]).withDefault(42); +// → prop type: string | number ``` ### `instanceOfProp(parent: T, validator?: Validator)` @@ -452,14 +452,14 @@ Allows instances of the given constructor (validated at runtime and compile time Type parameter `T` can be used to adjust the inferred type at compile time. ```ts -instanceOfProp(Date).optional - // → prop type: Date | undefined -instanceOfProp(Date).nullable - // → prop type: Date | null -instanceOfProp(Date).required - // → prop type: Date -instanceOfProp(Date).withDefault(() => new Date()) - // → prop type: Date +instanceOfProp(Date).optional; +// → prop type: Date | undefined +instanceOfProp(Date).nullable; +// → prop type: Date | null +instanceOfProp(Date).required; +// → prop type: Date +instanceOfProp(Date).withDefault(() => new Date()); +// → prop type: Date ``` ## Contributing @@ -468,9 +468,9 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md). ## Similar packages -* [vue-types](https://www.npmjs.com/package/vue-types/), which this project took heavy inspiration from -* [vue-prop](https://www.npmjs.com/package/vue-prop) -* [vuept](https://www.npmjs.com/package/vuept) +- [vue-types](https://www.npmjs.com/package/vue-types/), which this project took heavy inspiration from +- [vue-prop](https://www.npmjs.com/package/vue-prop) +- [vuept](https://www.npmjs.com/package/vuept) ## License diff --git a/src/prop-types/any.ts b/src/prop-types/any.ts index 9d7a3cd6..1e6cd836 100644 --- a/src/prop-types/any.ts +++ b/src/prop-types/any.ts @@ -9,5 +9,6 @@ import type { Validator } from '../validators'; * * @param validator - Optional function for runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const anyProp = (validator?: Validator): PropOptionsGenerator => - propOptionsGenerator(undefined, validator); +export const anyProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(undefined, validator); diff --git a/src/prop-types/array.ts b/src/prop-types/array.ts index 26fcbfe4..d0a63397 100644 --- a/src/prop-types/array.ts +++ b/src/prop-types/array.ts @@ -9,5 +9,6 @@ import type { Validator } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const arrayProp = (validator?: Validator): PropOptionsGenerator => - propOptionsGenerator(Array, validator); +export const arrayProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(Array, validator); diff --git a/src/prop-types/boolean.ts b/src/prop-types/boolean.ts index dcae4b04..bec7807b 100644 --- a/src/prop-types/boolean.ts +++ b/src/prop-types/boolean.ts @@ -7,5 +7,6 @@ import type { Validator } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const booleanProp = (validator?: Validator): PropOptionsGenerator => - propOptionsGenerator(Boolean, validator); +export const booleanProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(Boolean, validator); diff --git a/src/prop-types/function.ts b/src/prop-types/function.ts index ac3619c5..4387e897 100644 --- a/src/prop-types/function.ts +++ b/src/prop-types/function.ts @@ -17,7 +17,9 @@ interface FunctionPropOptionsGenerator { * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const functionProp = (validator?: Validator): FunctionPropOptionsGenerator => ({ +export const functionProp = ( + validator?: Validator, +): FunctionPropOptionsGenerator => ({ optional: { type: Function as unknown as () => T, required: false, diff --git a/src/prop-types/instanceOf.ts b/src/prop-types/instanceOf.ts index e05df8fc..8a206d77 100644 --- a/src/prop-types/instanceOf.ts +++ b/src/prop-types/instanceOf.ts @@ -11,5 +11,12 @@ import { isInstanceOf } from '../validators'; * @param parent - The constructor to allow. * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const instanceOfProp = (parent: T, validator?: Validator): PropOptionsGenerator> => - propOptionsGenerator>(parent, validator, isInstanceOf(parent)); +export const instanceOfProp = ( + parent: T, + validator?: Validator, +): PropOptionsGenerator> => + propOptionsGenerator>( + parent, + validator, + isInstanceOf(parent), + ); diff --git a/src/prop-types/integer.ts b/src/prop-types/integer.ts index a34aa7b2..d2a5aecd 100644 --- a/src/prop-types/integer.ts +++ b/src/prop-types/integer.ts @@ -8,5 +8,7 @@ import { isInteger } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const integerProp = (validator?: Validator): PropOptionsGenerator => +export const integerProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(Number, validator, isInteger); diff --git a/src/prop-types/number.ts b/src/prop-types/number.ts index 04e85b37..0353f7fb 100644 --- a/src/prop-types/number.ts +++ b/src/prop-types/number.ts @@ -9,5 +9,7 @@ import type { Validator } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const numberProp = (validator?: Validator): PropOptionsGenerator => +export const numberProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(Number as unknown as PropType, validator); diff --git a/src/prop-types/object.ts b/src/prop-types/object.ts index 60088be4..626cfd23 100644 --- a/src/prop-types/object.ts +++ b/src/prop-types/object.ts @@ -9,5 +9,6 @@ import type { Validator } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const objectProp = (validator?: Validator): PropOptionsGenerator => - propOptionsGenerator(Object, validator); +export const objectProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(Object, validator); diff --git a/src/prop-types/oneOf.ts b/src/prop-types/oneOf.ts index 797dac2a..3871ba5b 100644 --- a/src/prop-types/oneOf.ts +++ b/src/prop-types/oneOf.ts @@ -4,16 +4,22 @@ import type { Validator } from '../validators'; import { isOneOf } from '../validators'; // inspired by https://github.com/dwightjack/vue-types/blob/4.1.1/src/validators/oneof.ts -const getOneOfType = (values: T): PropType | undefined => { - const allowedTypes: PropConstructor[] = [...new Set( - values.flatMap(value => { - if (value === null || value === undefined) { - return []; - } - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - return ((value as any).constructor as PropConstructor | undefined) ?? []; - }), - )]; +const getOneOfType = ( + values: T, +): PropType | undefined => { + const allowedTypes: PropConstructor[] = [ + ...new Set( + values.flatMap((value) => { + if (value === null || value === undefined) { + return []; + } + return ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + ((value as any).constructor as PropConstructor | undefined) ?? [] + ); + }), + ), + ]; if (allowedTypes.length === 0) { return undefined; @@ -34,5 +40,12 @@ const getOneOfType = (values: T): PropType(allowedValues: T, validator?: Validator): PropOptionsGenerator => - propOptionsGenerator(getOneOfType(allowedValues), validator, isOneOf(allowedValues)); +export const oneOfProp = ( + allowedValues: T, + validator?: Validator, +): PropOptionsGenerator => + propOptionsGenerator( + getOneOfType(allowedValues), + validator, + isOneOf(allowedValues), + ); diff --git a/src/prop-types/oneOfObjectKeys.ts b/src/prop-types/oneOfObjectKeys.ts index dc78028b..72b938ce 100644 --- a/src/prop-types/oneOfObjectKeys.ts +++ b/src/prop-types/oneOfObjectKeys.ts @@ -2,7 +2,7 @@ import type { PropOptionsGenerator } from '../types'; import type { Validator } from '../validators'; import { oneOfProp } from './oneOf'; -type PlainObject = Record +type PlainObject = Record; /** * Allows any of the keys of the specified object (validated at runtime and compile time). @@ -12,5 +12,8 @@ type PlainObject = Record * @param object - The object whose keys are allowed. * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const oneOfObjectKeysProp = (object: T, validator?: Validator): PropOptionsGenerator => +export const oneOfObjectKeysProp = ( + object: T, + validator?: Validator, +): PropOptionsGenerator => oneOfProp(Object.keys(object) as (keyof T)[], validator); diff --git a/src/prop-types/oneOfTypes.ts b/src/prop-types/oneOfTypes.ts index 5594a6b9..e5ca070c 100644 --- a/src/prop-types/oneOfTypes.ts +++ b/src/prop-types/oneOfTypes.ts @@ -10,5 +10,7 @@ import type { Validator } from '../validators'; * @param type - A single constructor or an array of constructors to allow. * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const oneOfTypesProp = (type: PropType, validator?: Validator): PropOptionsGenerator => - propOptionsGenerator(type, validator); +export const oneOfTypesProp = ( + type: PropType, + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(type, validator); diff --git a/src/prop-types/string.ts b/src/prop-types/string.ts index 8b9ee5b3..2b9ba11f 100644 --- a/src/prop-types/string.ts +++ b/src/prop-types/string.ts @@ -9,5 +9,7 @@ import type { Validator } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const stringProp = (validator?: Validator): PropOptionsGenerator => +export const stringProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(String as unknown as PropType, validator); diff --git a/src/prop-types/symbol.ts b/src/prop-types/symbol.ts index 6ac15dff..e696c2bf 100644 --- a/src/prop-types/symbol.ts +++ b/src/prop-types/symbol.ts @@ -8,5 +8,7 @@ import { isSymbol } from '../validators'; * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const symbolProp = (validator?: Validator): PropOptionsGenerator => +export const symbolProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator(undefined, validator, isSymbol); diff --git a/src/prop-types/vueComponent.ts b/src/prop-types/vueComponent.ts index c6416315..de80ea39 100644 --- a/src/prop-types/vueComponent.ts +++ b/src/prop-types/vueComponent.ts @@ -3,12 +3,14 @@ import { propOptionsGenerator } from '../util'; import type { Validator } from '../validators'; /** Has to be so broad to allow Vue 2 and Vue 3 component options or instances. */ -export type VueComponent = object | string +export type VueComponent = object | string; /** * Allows any Vue component instance, name or options object. No built-in runtime validation is performed by default. * * @param validator - Optional function for further runtime validation; should return `undefined` if valid, or an error string if invalid. */ -export const vueComponentProp = (validator?: Validator): PropOptionsGenerator => +export const vueComponentProp = ( + validator?: Validator, +): PropOptionsGenerator => propOptionsGenerator([Object, String], validator); diff --git a/src/types.ts b/src/types.ts index a2c84b0e..360d7f5f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,17 +5,16 @@ export interface PropOptions { validator?(value: T): boolean; } -export type PropType = PropConstructor | PropConstructor[] +export type PropType = PropConstructor | PropConstructor[]; export type PropConstructor = // eslint-disable-next-line @typescript-eslint/prefer-function-type | { (): T } // eslint-disable-next-line @typescript-eslint/prefer-function-type - | { new(...parameters: any[]): T & object } + | { new (...parameters: any[]): T & object }; - -export type RequiredPropOptions = PropOptions & { required: true } -export type DefaultPropOptions = PropOptions & { default: unknown } +export type RequiredPropOptions = PropOptions & { required: true }; +export type DefaultPropOptions = PropOptions & { default: unknown }; export interface PropOptionsGenerator { optional: DefaultPropOptions; @@ -25,6 +24,14 @@ export interface PropOptionsGenerator { } /** Allow simple values for primitive types, require generator function for complex types */ -export type OneOfDefaultType = T extends boolean | number | string | symbol | null | undefined ? T : (() => T) +export type OneOfDefaultType = T extends + | boolean + | number + | string + | symbol + | null + | undefined + ? T + : () => T; -export type Constructor = new (...parameters: any[]) => any +export type Constructor = new (...parameters: any[]) => any; diff --git a/src/util.ts b/src/util.ts index c90efe2a..cb402b4f 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,8 +1,17 @@ -import type { DefaultPropOptions, OneOfDefaultType, PropOptionsGenerator, PropType } from './types'; +import type { + DefaultPropOptions, + OneOfDefaultType, + PropOptionsGenerator, + PropType, +} from './types'; import { vuePropValidator } from './validators'; import type { Validator } from './validators'; -export const propOptionsGenerator = (type?: PropType, userValidator?: Validator, ...typeValidators: Validator[]): PropOptionsGenerator => ({ +export const propOptionsGenerator = ( + type?: PropType, + userValidator?: Validator, + ...typeValidators: Validator[] +): PropOptionsGenerator => ({ optional: { type, required: false, diff --git a/src/validators/index.ts b/src/validators/index.ts index f47c78a0..646efd75 100644 --- a/src/validators/index.ts +++ b/src/validators/index.ts @@ -1,15 +1,20 @@ import Vue from 'vue'; -export type Validator = (value: unknown) => string | undefined -export type VuePropValidator = (value: unknown) => boolean +export type Validator = (value: unknown) => string | undefined; +export type VuePropValidator = (value: unknown) => boolean; /** * Creates a Vue prop validator that runs all type validators and the user validator (if specified). * @param userValidator Validator function specified by the user. * @param typeValidators Validator functions hard-coded by the prop type function. */ -export function vuePropValidator(userValidator?: Validator, ...typeValidators: Validator[]): VuePropValidator | undefined { - const validators = userValidator ? [...typeValidators, userValidator] : typeValidators; +export function vuePropValidator( + userValidator?: Validator, + ...typeValidators: Validator[] +): VuePropValidator | undefined { + const validators = userValidator + ? [...typeValidators, userValidator] + : typeValidators; if (validators.length === 0) { return undefined; } @@ -22,8 +27,7 @@ export function vuePropValidator(userValidator?: Validator, ...typeValidators: V // @ts-expect-error -- Vue.util is only available in Vue 2, but provides more context than console.warn // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call Vue.util.warn(`${errorMessage} (received: '${String(value)}')`); - } - else { + } else { console.warn(`${errorMessage} (received: '${String(value)}')`); } return false; diff --git a/src/validators/isInstanceOf.ts b/src/validators/isInstanceOf.ts index 2488b37d..29ffa005 100644 --- a/src/validators/isInstanceOf.ts +++ b/src/validators/isInstanceOf.ts @@ -2,9 +2,11 @@ import type { Constructor } from '../types'; import type { Validator } from '.'; /** Validator that only allows instances of the given parent. */ -export const isInstanceOf = (parent: Constructor): Validator => value => { - if (!(value instanceof parent)) { - return `value should be an instance of ${parent.name}`; - } - return undefined; -}; +export const isInstanceOf = + (parent: Constructor): Validator => + (value) => { + if (!(value instanceof parent)) { + return `value should be an instance of ${parent.name}`; + } + return undefined; + }; diff --git a/src/validators/isInteger.ts b/src/validators/isInteger.ts index cdebac79..4f827345 100644 --- a/src/validators/isInteger.ts +++ b/src/validators/isInteger.ts @@ -1,7 +1,7 @@ import type { Validator } from '.'; /** Validator that only allows integer numbers. */ -export const isInteger: Validator = value => { +export const isInteger: Validator = (value) => { if (typeof value !== 'number' || !Number.isInteger(value)) { return 'value should be an integer'; } diff --git a/src/validators/isNegative.ts b/src/validators/isNegative.ts index 3901bc8f..9e5516a4 100644 --- a/src/validators/isNegative.ts +++ b/src/validators/isNegative.ts @@ -1,7 +1,7 @@ import type { Validator } from '.'; /** Validator that only allows negative numbers (`< 0`). */ -export const isNegative: Validator = value => { +export const isNegative: Validator = (value) => { if (typeof value !== 'number' || value >= 0 || Number.isNaN(value)) { return 'value should be a negative number'; } diff --git a/src/validators/isNonNegative.ts b/src/validators/isNonNegative.ts index 220c2a56..d2935a53 100644 --- a/src/validators/isNonNegative.ts +++ b/src/validators/isNonNegative.ts @@ -1,7 +1,7 @@ import type { Validator } from '.'; /** Validator that only allows non-negative numbers (`>= 0`). */ -export const isNonNegative: Validator = value => { +export const isNonNegative: Validator = (value) => { if (typeof value !== 'number' || value < 0 || Number.isNaN(value)) { return 'value should be a non-negative number'; } diff --git a/src/validators/isNonPositive.ts b/src/validators/isNonPositive.ts index a3667e39..076a6cd7 100644 --- a/src/validators/isNonPositive.ts +++ b/src/validators/isNonPositive.ts @@ -1,7 +1,7 @@ import type { Validator } from '.'; /** Validator that only allows non-positive numbers (`<= 0`). */ -export const isNonPositive: Validator = value => { +export const isNonPositive: Validator = (value) => { if (typeof value !== 'number' || value > 0 || Number.isNaN(value)) { return 'value should be a non-positive number'; } diff --git a/src/validators/isOneOf.ts b/src/validators/isOneOf.ts index 1a1bfce6..b7e1ff53 100644 --- a/src/validators/isOneOf.ts +++ b/src/validators/isOneOf.ts @@ -1,9 +1,11 @@ import type { Validator } from '.'; /** Validator that only allows any of the given values. */ -export const isOneOf = (allowedValues: readonly unknown[]): Validator => value => { - if (!allowedValues.includes(value)) { - return `value should be one of "${allowedValues.join('", "')}"`; - } - return undefined; -}; +export const isOneOf = + (allowedValues: readonly unknown[]): Validator => + (value) => { + if (!allowedValues.includes(value)) { + return `value should be one of "${allowedValues.join('", "')}"`; + } + return undefined; + }; diff --git a/src/validators/isPositive.ts b/src/validators/isPositive.ts index fb691e16..2fbe77c1 100644 --- a/src/validators/isPositive.ts +++ b/src/validators/isPositive.ts @@ -1,7 +1,7 @@ import type { Validator } from '.'; /** Validator that only allows positive numbers (`> 0`). */ -export const isPositive: Validator = value => { +export const isPositive: Validator = (value) => { if (typeof value !== 'number' || value <= 0 || Number.isNaN(value)) { return 'value should be a positive number'; } diff --git a/src/validators/isSymbol.ts b/src/validators/isSymbol.ts index c2f78e0f..f918c673 100644 --- a/src/validators/isSymbol.ts +++ b/src/validators/isSymbol.ts @@ -1,7 +1,7 @@ import type { Validator } from '.'; /** Validator that only allows symbols. */ -export const isSymbol: Validator = value => { +export const isSymbol: Validator = (value) => { if (typeof value !== 'symbol') { return 'value should be a symbol'; } diff --git a/tests/prop-types/oneOf.spec.ts b/tests/prop-types/oneOf.spec.ts index a9c586a8..9b9136ba 100644 --- a/tests/prop-types/oneOf.spec.ts +++ b/tests/prop-types/oneOf.spec.ts @@ -11,12 +11,23 @@ describe('oneOfProp().optional', () => { }); it('has the correct type', () => { - expect(oneOfProp(['a', 'b', 'c'] as const).optional.type).toStrictEqual(String); + expect(oneOfProp(['a', 'b', 'c'] as const).optional.type).toStrictEqual( + String, + ); expect(oneOfProp([1, 2, 3] as const).optional.type).toStrictEqual(Number); - expect(oneOfProp(['foo', 1, 2, 3] as const).optional.type).toStrictEqual([String, Number]); - expect(oneOfProp([true, false, 'both'] as const).optional.type).toStrictEqual([Boolean, String]); - expect(oneOfProp([undefined, null] as const).optional.type).toStrictEqual(undefined); - expect(oneOfProp([undefined, 'defined'] as const).optional.type).toStrictEqual(String); + expect(oneOfProp(['foo', 1, 2, 3] as const).optional.type).toStrictEqual([ + String, + Number, + ]); + expect( + oneOfProp([true, false, 'both'] as const).optional.type, + ).toStrictEqual([Boolean, String]); + expect(oneOfProp([undefined, null] as const).optional.type).toStrictEqual( + undefined, + ); + expect( + oneOfProp([undefined, 'defined'] as const).optional.type, + ).toStrictEqual(String); }); }); @@ -31,12 +42,23 @@ describe('oneOfProp().nullable', () => { }); it('has the correct type', () => { - expect(oneOfProp(['a', 'b', 'c'] as const).nullable.type).toStrictEqual(String); + expect(oneOfProp(['a', 'b', 'c'] as const).nullable.type).toStrictEqual( + String, + ); expect(oneOfProp([1, 2, 3] as const).nullable.type).toStrictEqual(Number); - expect(oneOfProp(['foo', 1, 2, 3] as const).nullable.type).toStrictEqual([String, Number]); - expect(oneOfProp([true, false, 'both'] as const).nullable.type).toStrictEqual([Boolean, String]); - expect(oneOfProp([undefined, null] as const).nullable.type).toStrictEqual(undefined); - expect(oneOfProp([undefined, 'defined'] as const).nullable.type).toStrictEqual(String); + expect(oneOfProp(['foo', 1, 2, 3] as const).nullable.type).toStrictEqual([ + String, + Number, + ]); + expect( + oneOfProp([true, false, 'both'] as const).nullable.type, + ).toStrictEqual([Boolean, String]); + expect(oneOfProp([undefined, null] as const).nullable.type).toStrictEqual( + undefined, + ); + expect( + oneOfProp([undefined, 'defined'] as const).nullable.type, + ).toStrictEqual(String); }); }); diff --git a/tests/prop-types/oneOfTypes.spec.ts b/tests/prop-types/oneOfTypes.spec.ts index 5892529d..23081a18 100644 --- a/tests/prop-types/oneOfTypes.spec.ts +++ b/tests/prop-types/oneOfTypes.spec.ts @@ -2,7 +2,9 @@ import { oneOfTypesProp } from '../../src/prop-types/oneOfTypes'; describe('oneOfTypesProp().optional', () => { it('creates the correct prop options', () => { - expect(oneOfTypesProp([Number, String]).optional).toStrictEqual({ + expect( + oneOfTypesProp([Number, String]).optional, + ).toStrictEqual({ type: [Number, String], required: false, default: undefined, @@ -13,7 +15,9 @@ describe('oneOfTypesProp().optional', () => { describe('oneOfTypesProp().nullable', () => { it('creates the correct prop options', () => { - expect(oneOfTypesProp([Number, String]).nullable).toStrictEqual({ + expect( + oneOfTypesProp([Number, String]).nullable, + ).toStrictEqual({ type: [Number, String], required: false, default: null, @@ -24,7 +28,9 @@ describe('oneOfTypesProp().nullable', () => { describe('oneOfTypesProp().withDefault', () => { it('creates the correct prop options', () => { - expect(oneOfTypesProp([Number, String]).withDefault('a')).toStrictEqual({ + expect( + oneOfTypesProp([Number, String]).withDefault('a'), + ).toStrictEqual({ type: [Number, String], required: false, default: 'a', @@ -35,7 +41,9 @@ describe('oneOfTypesProp().withDefault', () => { describe('oneOfTypesProp().required', () => { it('creates the correct prop options', () => { - expect(oneOfTypesProp([Number, String]).required).toStrictEqual({ + expect( + oneOfTypesProp([Number, String]).required, + ).toStrictEqual({ type: [Number, String], required: true, validator: undefined, diff --git a/tests/validators/index.spec.ts b/tests/validators/index.spec.ts index 68613022..12fc8c9f 100644 --- a/tests/validators/index.spec.ts +++ b/tests/validators/index.spec.ts @@ -20,13 +20,11 @@ describe('vuePropValidator', () => { describe('returned Vue validator', () => { it('returns true if all validators pass', () => { - expect( - vuePropValidator(undefined, validator1, validator2)!('foo'), - ).toBe(true); + expect(vuePropValidator(undefined, validator1, validator2)!('foo')).toBe( + true, + ); - expect( - vuePropValidator(validator1, validator2)!('foo'), - ).toBe(true); + expect(vuePropValidator(validator1, validator2)!('foo')).toBe(true); }); it('does not warn all validators pass', () => { @@ -35,22 +33,28 @@ describe('vuePropValidator', () => { }); it('returns false if any validator fails', () => { - expect( - vuePropValidator(undefined, validator3, validator2)!('foo'), - ).toBe(false); + expect(vuePropValidator(undefined, validator3, validator2)!('foo')).toBe( + false, + ); - expect( - vuePropValidator(validator3, validator2)!('foo'), - ).toBe(false); + expect(vuePropValidator(validator3, validator2)!('foo')).toBe(false); }); it('warns if any validator fails', () => { vuePropValidator(undefined, validator3, validator2)!('foo'); - expect(warnSpy).toHaveBeenCalledWith('some error message (received: \'foo\')'); + expect(warnSpy).toHaveBeenCalledWith( + "some error message (received: 'foo')", + ); }); it('calls all validators in order until one fails', () => { - vuePropValidator(undefined, validator1, validator2, validator3, validator4)!('foo'); + vuePropValidator( + undefined, + validator1, + validator2, + validator3, + validator4, + )!('foo'); expect(validator1).toHaveBeenCalledWith('foo'); expect(validator1).toHaveBeenCalledBefore(validator2); diff --git a/tests/validators/isInstanceOf.spec.ts b/tests/validators/isInstanceOf.spec.ts index 854ddc79..ca721a82 100644 --- a/tests/validators/isInstanceOf.spec.ts +++ b/tests/validators/isInstanceOf.spec.ts @@ -28,16 +28,16 @@ describe('isInstanceOf', () => { it('throws if parent is not a constructor', () => { const user1 = new User(); - expect( - () => isInstanceOf(undefined as any)(user1), - ).toThrow('Right-hand side of \'instanceof\' is not an object'); + expect(() => isInstanceOf(undefined as any)(user1)).toThrow( + "Right-hand side of 'instanceof' is not an object", + ); - expect( - () => isInstanceOf([] as any)(user1), - ).toThrow('Right-hand side of \'instanceof\' is not callable'); + expect(() => isInstanceOf([] as any)(user1)).toThrow( + "Right-hand side of 'instanceof' is not callable", + ); - expect( - () => isInstanceOf({} as any)(user1), - ).toThrow('Right-hand side of \'instanceof\' is not callable'); + expect(() => isInstanceOf({} as any)(user1)).toThrow( + "Right-hand side of 'instanceof' is not callable", + ); }); }); diff --git a/tsconfig.json b/tsconfig.json index c8ad1020..dfe2b070 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,8 +10,5 @@ "strict": true, "skipLibCheck": true }, - "include": [ - ".eslintrc.cjs", - "**/*.ts" - ] + "include": [".eslintrc.cjs", "**/*.ts"] } diff --git a/type-tests/prop-types/any.type.spec.ts b/type-tests/prop-types/any.type.spec.ts index 80e2acb2..fe10165e 100644 --- a/type-tests/prop-types/any.type.spec.ts +++ b/type-tests/prop-types/any.type.spec.ts @@ -11,7 +11,9 @@ describe('anyProp().optional', () => { expectAssignable(anyProp().optional); expectAssignable>(anyProp().optional); expectAssignable>(anyProp().optional); - expectAssignable>(anyProp().optional); + expectAssignable>( + anyProp().optional, + ); expectNotAssignable>(anyProp().optional); expectType>( @@ -27,7 +29,9 @@ describe('anyProp().optional', () => { expectAssignable(anyProp().optional); expectAssignable>(anyProp().optional); expectAssignable>(anyProp().optional); - expectAssignable>(anyProp().optional); + expectAssignable>( + anyProp().optional, + ); expectNotAssignable>(anyProp().optional); }); @@ -45,7 +49,9 @@ describe('anyProp().nullable', () => { expectAssignable(anyProp().nullable); expectAssignable>(anyProp().nullable); expectAssignable>(anyProp().nullable); - expectAssignable>(anyProp().nullable); + expectAssignable>( + anyProp().nullable, + ); expectNotAssignable>(anyProp().nullable); expectType>( @@ -61,7 +67,9 @@ describe('anyProp().nullable', () => { expectAssignable(anyProp().nullable); expectAssignable>(anyProp().nullable); expectAssignable>(anyProp().nullable); - expectAssignable>(anyProp().nullable); + expectAssignable>( + anyProp().nullable, + ); expectNotAssignable>(anyProp().nullable); }); @@ -79,8 +87,12 @@ describe('anyProp().withDefault', () => { expectAssignable(anyProp().withDefault('foo')); expectAssignable>(anyProp().withDefault('foo')); expectAssignable>(anyProp().withDefault('foo')); - expectAssignable>(anyProp().withDefault('foo')); - expectNotAssignable>(anyProp().withDefault('foo')); + expectAssignable>( + anyProp().withDefault('foo'), + ); + expectNotAssignable>( + anyProp().withDefault('foo'), + ); expectType>( createVue2Component(anyProp().withDefault('foo')), @@ -95,8 +107,12 @@ describe('anyProp().withDefault', () => { expectAssignable(anyProp().withDefault('foo')); expectAssignable>(anyProp().withDefault('foo')); expectAssignable>(anyProp().withDefault('foo')); - expectAssignable>(anyProp().withDefault('foo')); - expectNotAssignable>(anyProp().withDefault('foo')); + expectAssignable>( + anyProp().withDefault('foo'), + ); + expectNotAssignable>( + anyProp().withDefault('foo'), + ); }); describe('Vue 3', () => { @@ -104,7 +120,9 @@ describe('anyProp().withDefault', () => { expectAssignable>(anyProp().withDefault('foo')); expectAssignable>(anyProp().withDefault('foo')); expectAssignable>(anyProp().withDefault('foo')); - expectNotAssignable>(anyProp().withDefault('foo')); + expectNotAssignable>( + anyProp().withDefault('foo'), + ); }); }); diff --git a/type-tests/prop-types/array.type.spec.ts b/type-tests/prop-types/array.type.spec.ts index 2ce017c8..656305b7 100644 --- a/type-tests/prop-types/array.type.spec.ts +++ b/type-tests/prop-types/array.type.spec.ts @@ -8,10 +8,16 @@ import type { Vue2ComponentWithProp } from '../utils'; describe('arrayProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(arrayProp().optional); - expectAssignable>(arrayProp().optional); + expectAssignable>( + arrayProp().optional, + ); + expectAssignable>( + arrayProp().optional, + ); expectNotAssignable>(arrayProp().optional); - expectNotAssignable>(arrayProp().optional); + expectNotAssignable>( + arrayProp().optional, + ); expectType>( createVue2Component(arrayProp().optional), @@ -23,15 +29,23 @@ describe('arrayProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(arrayProp().optional); - expectAssignable>(arrayProp().optional); + expectAssignable>( + arrayProp().optional, + ); + expectAssignable>( + arrayProp().optional, + ); expectNotAssignable>(arrayProp().optional); - expectNotAssignable>(arrayProp().optional); + expectNotAssignable>( + arrayProp().optional, + ); }); describe('Vue 3', () => { expectAssignable>(arrayProp().optional); - expectAssignable>(arrayProp().optional); + expectAssignable>( + arrayProp().optional, + ); expectNotAssignable>(arrayProp().optional); expectNotAssignable>(arrayProp().optional); }); @@ -39,10 +53,16 @@ describe('arrayProp().optional', () => { describe('arrayProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(arrayProp().nullable); - expectAssignable>(arrayProp().nullable); + expectAssignable>( + arrayProp().nullable, + ); + expectAssignable>( + arrayProp().nullable, + ); expectNotAssignable>(arrayProp().nullable); - expectNotAssignable>(arrayProp().nullable); + expectNotAssignable>( + arrayProp().nullable, + ); expectType>( createVue2Component(arrayProp().nullable), @@ -54,10 +74,16 @@ describe('arrayProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(arrayProp().nullable); - expectAssignable>(arrayProp().nullable); + expectAssignable>( + arrayProp().nullable, + ); + expectAssignable>( + arrayProp().nullable, + ); expectNotAssignable>(arrayProp().nullable); - expectNotAssignable>(arrayProp().nullable); + expectNotAssignable>( + arrayProp().nullable, + ); }); describe('Vue 3', () => { @@ -70,33 +96,57 @@ describe('arrayProp().nullable', () => { describe('arrayProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); - expectNotAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); - expectAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); + expectAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); + expectNotAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); + expectAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); expectType>( - createVue2Component(arrayProp().withDefault(() => ['foo', 'bar'])), + createVue2Component( + arrayProp().withDefault(() => ['foo', 'bar']), + ), ); }); describe('Vue 2.7', () => { - expectAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); - expectNotAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); - expectAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); + expectAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); + expectNotAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); + expectAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); }); describe('Vue 3', () => { - expectAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); - expectNotAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); - expectAssignable>(arrayProp().withDefault(() => ['foo', 'bar'])); + expectAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); + expectNotAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); + expectAssignable>( + arrayProp().withDefault(() => ['foo', 'bar']), + ); }); }); describe('arrayProp().required', () => { describe('Vue 2.6', () => { expectAssignable>(arrayProp().required); - expectAssignable>(arrayProp().required); - expectNotAssignable>(arrayProp().required); + expectAssignable>( + arrayProp().required, + ); + expectNotAssignable>( + arrayProp().required, + ); expectType>( createVue2Component(arrayProp().required), @@ -109,8 +159,12 @@ describe('arrayProp().required', () => { describe('Vue 2.7', () => { expectAssignable>(arrayProp().required); - expectAssignable>(arrayProp().required); - expectNotAssignable>(arrayProp().required); + expectAssignable>( + arrayProp().required, + ); + expectNotAssignable>( + arrayProp().required, + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/boolean.type.spec.ts b/type-tests/prop-types/boolean.type.spec.ts index 370b5a8e..b0870c15 100644 --- a/type-tests/prop-types/boolean.type.spec.ts +++ b/type-tests/prop-types/boolean.type.spec.ts @@ -8,7 +8,9 @@ import type { Vue2ComponentWithProp } from '../utils'; describe('booleanProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(booleanProp().optional); + expectAssignable>( + booleanProp().optional, + ); expectNotAssignable>(booleanProp().optional); expectType>( @@ -17,7 +19,9 @@ describe('booleanProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(booleanProp().optional); + expectAssignable>( + booleanProp().optional, + ); expectNotAssignable>(booleanProp().optional); }); @@ -29,7 +33,9 @@ describe('booleanProp().optional', () => { describe('booleanProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(booleanProp().nullable); + expectAssignable>( + booleanProp().nullable, + ); expectNotAssignable>(booleanProp().nullable); expectType>( @@ -38,7 +44,9 @@ describe('booleanProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(booleanProp().nullable); + expectAssignable>( + booleanProp().nullable, + ); expectNotAssignable>(booleanProp().nullable); }); @@ -50,8 +58,12 @@ describe('booleanProp().nullable', () => { describe('booleanProp().withDefault(false)', () => { describe('Vue 2.6', () => { - expectAssignable>(booleanProp().withDefault(false)); - expectNotAssignable>(booleanProp().withDefault(false)); + expectAssignable>( + booleanProp().withDefault(false), + ); + expectNotAssignable>( + booleanProp().withDefault(false), + ); expectType>( createVue2Component(booleanProp().withDefault(false)), @@ -59,8 +71,12 @@ describe('booleanProp().withDefault(false)', () => { }); describe('Vue 2.7', () => { - expectAssignable>(booleanProp().withDefault(false)); - expectNotAssignable>(booleanProp().withDefault(false)); + expectAssignable>( + booleanProp().withDefault(false), + ); + expectNotAssignable>( + booleanProp().withDefault(false), + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/function.type.spec.ts b/type-tests/prop-types/function.type.spec.ts index ea0553a1..d1010a57 100644 --- a/type-tests/prop-types/function.type.spec.ts +++ b/type-tests/prop-types/function.type.spec.ts @@ -8,14 +8,20 @@ import type { Vue2ComponentWithProp } from '../utils'; /* eslint-disable @typescript-eslint/ban-types */ -type MyCustomCallback = (parameter: string) => Promise +type MyCustomCallback = (parameter: string) => Promise; describe('functionProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(functionProp().optional); - expectAssignable>(functionProp().optional); + expectAssignable>( + functionProp().optional, + ); + expectAssignable>( + functionProp().optional, + ); expectNotAssignable>(functionProp().optional); - expectNotAssignable>(functionProp().optional); + expectNotAssignable>( + functionProp().optional, + ); expectType>( createVue2Component(functionProp().optional), @@ -27,26 +33,42 @@ describe('functionProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(functionProp().optional); - expectAssignable>(functionProp().optional); + expectAssignable>( + functionProp().optional, + ); + expectAssignable>( + functionProp().optional, + ); expectNotAssignable>(functionProp().optional); - expectNotAssignable>(functionProp().optional); + expectNotAssignable>( + functionProp().optional, + ); }); describe('Vue 3', () => { expectAssignable>(functionProp().optional); - expectAssignable>(functionProp().optional); + expectAssignable>( + functionProp().optional, + ); expectNotAssignable>(functionProp().optional); - expectNotAssignable>(functionProp().optional); + expectNotAssignable>( + functionProp().optional, + ); }); }); describe('functionProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(functionProp().nullable); - expectAssignable>(functionProp().nullable); + expectAssignable>( + functionProp().nullable, + ); + expectAssignable>( + functionProp().nullable, + ); expectNotAssignable>(functionProp().nullable); - expectNotAssignable>(functionProp().nullable); + expectNotAssignable>( + functionProp().nullable, + ); expectType>( createVue2Component(functionProp().nullable), @@ -58,24 +80,36 @@ describe('functionProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(functionProp().nullable); - expectAssignable>(functionProp().nullable); + expectAssignable>( + functionProp().nullable, + ); + expectAssignable>( + functionProp().nullable, + ); expectNotAssignable>(functionProp().nullable); - expectNotAssignable>(functionProp().nullable); + expectNotAssignable>( + functionProp().nullable, + ); }); describe('Vue 3', () => { expectAssignable>(functionProp().nullable); - expectAssignable>(functionProp().nullable); + expectAssignable>( + functionProp().nullable, + ); expectNotAssignable>(functionProp().nullable); - expectNotAssignable>(functionProp().nullable); + expectNotAssignable>( + functionProp().nullable, + ); }); }); describe('functionProp().required', () => { describe('Vue 2.6', () => { expectAssignable>(functionProp().required); - expectAssignable>(functionProp().required); + expectAssignable>( + functionProp().required, + ); expectNotAssignable>(functionProp().required); expectType>( @@ -89,13 +123,17 @@ describe('functionProp().required', () => { describe('Vue 2.7', () => { expectAssignable>(functionProp().required); - expectAssignable>(functionProp().required); + expectAssignable>( + functionProp().required, + ); expectNotAssignable>(functionProp().required); }); describe('Vue 3', () => { expectAssignable>(functionProp().required); - expectAssignable>(functionProp().required); + expectAssignable>( + functionProp().required, + ); expectNotAssignable>(functionProp().required); }); }); diff --git a/type-tests/prop-types/instanceOf.type.spec.ts b/type-tests/prop-types/instanceOf.type.spec.ts index dfd69ccc..9a876e61 100644 --- a/type-tests/prop-types/instanceOf.type.spec.ts +++ b/type-tests/prop-types/instanceOf.type.spec.ts @@ -15,8 +15,12 @@ class Account { describe('instanceOfProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(instanceOfProp(User).optional); - expectNotAssignable>(instanceOfProp(User).optional); + expectAssignable>( + instanceOfProp(User).optional, + ); + expectNotAssignable>( + instanceOfProp(User).optional, + ); expectType>( createVue2Component(instanceOfProp(User).optional), @@ -24,20 +28,30 @@ describe('instanceOfProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(instanceOfProp(User).optional); - expectNotAssignable>(instanceOfProp(User).optional); + expectAssignable>( + instanceOfProp(User).optional, + ); + expectNotAssignable>( + instanceOfProp(User).optional, + ); }); describe('Vue 3', () => { - expectAssignable>(instanceOfProp(User).optional); + expectAssignable>( + instanceOfProp(User).optional, + ); expectNotAssignable>(instanceOfProp(User).optional); }); }); describe('instanceOfProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(instanceOfProp(User).optional); - expectNotAssignable>(instanceOfProp(User).optional); + expectAssignable>( + instanceOfProp(User).optional, + ); + expectNotAssignable>( + instanceOfProp(User).optional, + ); expectType>( createVue2Component(instanceOfProp(User).optional), @@ -45,20 +59,30 @@ describe('instanceOfProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(instanceOfProp(User).optional); - expectNotAssignable>(instanceOfProp(User).optional); + expectAssignable>( + instanceOfProp(User).optional, + ); + expectNotAssignable>( + instanceOfProp(User).optional, + ); }); describe('Vue 3', () => { - expectAssignable>(instanceOfProp(User).optional); + expectAssignable>( + instanceOfProp(User).optional, + ); expectNotAssignable>(instanceOfProp(User).optional); }); }); describe('instanceOfProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(instanceOfProp(User).withDefault(() => new User())); - expectNotAssignable>(instanceOfProp(User).withDefault(() => new User())); + expectAssignable>( + instanceOfProp(User).withDefault(() => new User()), + ); + expectNotAssignable>( + instanceOfProp(User).withDefault(() => new User()), + ); expectType>( createVue2Component(instanceOfProp(User).withDefault(() => new User())), @@ -66,20 +90,30 @@ describe('instanceOfProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(instanceOfProp(User).withDefault(() => new User())); - expectNotAssignable>(instanceOfProp(User).withDefault(() => new User())); + expectAssignable>( + instanceOfProp(User).withDefault(() => new User()), + ); + expectNotAssignable>( + instanceOfProp(User).withDefault(() => new User()), + ); }); describe('Vue 3', () => { - expectAssignable>(instanceOfProp(User).withDefault(() => new User())); - expectNotAssignable>(instanceOfProp(User).withDefault(() => new User())); + expectAssignable>( + instanceOfProp(User).withDefault(() => new User()), + ); + expectNotAssignable>( + instanceOfProp(User).withDefault(() => new User()), + ); }); }); describe('instanceOfProp().required', () => { describe('Vue 2.6', () => { expectAssignable>(instanceOfProp(User).required); - expectNotAssignable>(instanceOfProp(User).required); + expectNotAssignable>( + instanceOfProp(User).required, + ); expectType>( createVue2Component(instanceOfProp(User).required), @@ -88,7 +122,9 @@ describe('instanceOfProp().required', () => { describe('Vue 2.7', () => { expectAssignable>(instanceOfProp(User).required); - expectNotAssignable>(instanceOfProp(User).required); + expectNotAssignable>( + instanceOfProp(User).required, + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/integer.type.spec.ts b/type-tests/prop-types/integer.type.spec.ts index 31fd8fd0..74d882a7 100644 --- a/type-tests/prop-types/integer.type.spec.ts +++ b/type-tests/prop-types/integer.type.spec.ts @@ -8,7 +8,9 @@ import type { Vue2ComponentWithProp } from '../utils'; describe('integerProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(integerProp().optional); + expectAssignable>( + integerProp().optional, + ); expectNotAssignable>(integerProp().optional); expectType>( @@ -17,7 +19,9 @@ describe('integerProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(integerProp().optional); + expectAssignable>( + integerProp().optional, + ); expectNotAssignable>(integerProp().optional); }); @@ -51,7 +55,9 @@ describe('integerProp().nullable', () => { describe('integerProp().withDefault', () => { describe('Vue 2.6', () => { expectAssignable>(integerProp().withDefault(27)); - expectNotAssignable>(integerProp().withDefault(27)); + expectNotAssignable>( + integerProp().withDefault(27), + ); expectType>( createVue2Component(integerProp().withDefault(27)), @@ -60,7 +66,9 @@ describe('integerProp().withDefault', () => { describe('Vue 2.7', () => { expectAssignable>(integerProp().withDefault(27)); - expectNotAssignable>(integerProp().withDefault(27)); + expectNotAssignable>( + integerProp().withDefault(27), + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/number.type.spec.ts b/type-tests/prop-types/number.type.spec.ts index 0fd60efc..8e0b37e8 100644 --- a/type-tests/prop-types/number.type.spec.ts +++ b/type-tests/prop-types/number.type.spec.ts @@ -10,7 +10,9 @@ type Foo = 1 | 2 | 3; describe('numberProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(numberProp().optional); + expectAssignable>( + numberProp().optional, + ); expectNotAssignable>(numberProp().optional); expectType>( @@ -23,8 +25,12 @@ describe('numberProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(numberProp().optional); - expectAssignable>(numberProp().optional); + expectAssignable>( + numberProp().optional, + ); + expectAssignable>( + numberProp().optional, + ); expectNotAssignable>(numberProp().optional); }); @@ -38,7 +44,9 @@ describe('numberProp().optional', () => { describe('numberProp().nullable', () => { describe('Vue 2.6', () => { expectAssignable>(numberProp().nullable); - expectAssignable>(numberProp().nullable); + expectAssignable>( + numberProp().nullable, + ); expectNotAssignable>(numberProp().nullable); expectNotAssignable>(numberProp().nullable); @@ -53,7 +61,9 @@ describe('numberProp().nullable', () => { describe('Vue 2.7', () => { expectAssignable>(numberProp().nullable); - expectAssignable>(numberProp().nullable); + expectAssignable>( + numberProp().nullable, + ); expectNotAssignable>(numberProp().nullable); }); @@ -69,7 +79,9 @@ describe('numberProp().withDefault', () => { describe('Vue 2.6', () => { expectAssignable>(numberProp().withDefault(27)); expectAssignable>(numberProp().withDefault(1)); - expectNotAssignable>(numberProp().withDefault(27)); + expectNotAssignable>( + numberProp().withDefault(27), + ); expectType>( createVue2Component(numberProp().withDefault(27)), @@ -83,8 +95,12 @@ describe('numberProp().withDefault', () => { describe('Vue 2.7', () => { expectAssignable>(numberProp().withDefault(27)); expectAssignable>(numberProp().withDefault(1)); - expectNotAssignable>(numberProp().withDefault(27)); - expectNotAssignable>(numberProp().withDefault(1)); + expectNotAssignable>( + numberProp().withDefault(27), + ); + expectNotAssignable>( + numberProp().withDefault(1), + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/object.type.spec.ts b/type-tests/prop-types/object.type.spec.ts index da5d58c8..aebb9572 100644 --- a/type-tests/prop-types/object.type.spec.ts +++ b/type-tests/prop-types/object.type.spec.ts @@ -12,8 +12,12 @@ interface User { describe('objectProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(objectProp().optional); - expectAssignable>(objectProp().optional); + expectAssignable>( + objectProp().optional, + ); + expectAssignable>( + objectProp().optional, + ); expectNotAssignable>(objectProp().optional); expectType>( @@ -26,8 +30,12 @@ describe('objectProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(objectProp().optional); - expectAssignable>(objectProp().optional); + expectAssignable>( + objectProp().optional, + ); + expectAssignable>( + objectProp().optional, + ); expectNotAssignable>(objectProp().optional); }); @@ -41,7 +49,9 @@ describe('objectProp().optional', () => { describe('objectProp().nullable', () => { describe('Vue 2.6', () => { expectAssignable>(objectProp().nullable); - expectAssignable>(objectProp().nullable); + expectAssignable>( + objectProp().nullable, + ); expectNotAssignable>(objectProp().nullable); expectType>( @@ -55,7 +65,9 @@ describe('objectProp().nullable', () => { describe('Vue 2.7', () => { expectAssignable>(objectProp().nullable); - expectAssignable>(objectProp().nullable); + expectAssignable>( + objectProp().nullable, + ); expectNotAssignable>(objectProp().nullable); }); @@ -70,7 +82,9 @@ const userGenerator = () => ({ name: 'bar' }); describe('objectProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(objectProp().withDefault(userGenerator)); + expectAssignable>( + objectProp().withDefault(userGenerator), + ); expectType>( createVue2Component(objectProp().withDefault(userGenerator)), @@ -78,11 +92,15 @@ describe('objectProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(objectProp().withDefault(userGenerator)); + expectAssignable>( + objectProp().withDefault(userGenerator), + ); }); describe('Vue 3', () => { - expectAssignable>(objectProp().withDefault(userGenerator)); + expectAssignable>( + objectProp().withDefault(userGenerator), + ); }); }); diff --git a/type-tests/prop-types/oneOf.type.spec.ts b/type-tests/prop-types/oneOf.type.spec.ts index d2cf05e4..bedee456 100644 --- a/type-tests/prop-types/oneOf.type.spec.ts +++ b/type-tests/prop-types/oneOf.type.spec.ts @@ -11,8 +11,12 @@ type Options = 'a' | 'b' | 'c'; describe('oneOfProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfProp(['a', 'b', 'c']).optional); - expectAssignable>(oneOfProp(options).optional); + expectAssignable>( + oneOfProp(['a', 'b', 'c']).optional, + ); + expectAssignable>( + oneOfProp(options).optional, + ); expectType>( createVue2Component(oneOfProp(options).optional), @@ -20,20 +24,32 @@ describe('oneOfProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfProp(['a', 'b', 'c']).optional); - expectAssignable>(oneOfProp(options).optional); + expectAssignable>( + oneOfProp(['a', 'b', 'c']).optional, + ); + expectAssignable>( + oneOfProp(options).optional, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfProp(['a', 'b', 'c']).optional); - expectAssignable>(oneOfProp(options).optional); + expectAssignable>( + oneOfProp(['a', 'b', 'c']).optional, + ); + expectAssignable>( + oneOfProp(options).optional, + ); }); }); describe('oneOfProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfProp(['a', 'b', 'c']).nullable); - expectAssignable>(oneOfProp(options).nullable); + expectAssignable>( + oneOfProp(['a', 'b', 'c']).nullable, + ); + expectAssignable>( + oneOfProp(options).nullable, + ); expectType>( createVue2Component(oneOfProp(options).nullable), @@ -41,19 +57,27 @@ describe('oneOfProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfProp(['a', 'b', 'c']).nullable); - expectAssignable>(oneOfProp(options).nullable); + expectAssignable>( + oneOfProp(['a', 'b', 'c']).nullable, + ); + expectAssignable>( + oneOfProp(options).nullable, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfProp(['a', 'b', 'c']).nullable); + expectAssignable>( + oneOfProp(['a', 'b', 'c']).nullable, + ); expectAssignable>(oneOfProp(options).nullable); }); }); describe('oneOfProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfProp(options).withDefault('a')); + expectAssignable>( + oneOfProp(options).withDefault('a'), + ); expectType>( createVue2Component(oneOfProp(options).withDefault('a')), @@ -61,7 +85,9 @@ describe('oneOfProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfProp(options).withDefault('a')); + expectAssignable>( + oneOfProp(options).withDefault('a'), + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/oneOfObjectKeys.type.spec.ts b/type-tests/prop-types/oneOfObjectKeys.type.spec.ts index 8effa313..80189dd9 100644 --- a/type-tests/prop-types/oneOfObjectKeys.type.spec.ts +++ b/type-tests/prop-types/oneOfObjectKeys.type.spec.ts @@ -11,7 +11,9 @@ type Options = 'a' | 'b' | 'c'; describe('oneOfObjectKeysProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfObjectKeysProp(options).optional); + expectAssignable>( + oneOfObjectKeysProp(options).optional, + ); expectType>( createVue2Component(oneOfObjectKeysProp(options).optional), @@ -19,17 +21,23 @@ describe('oneOfObjectKeysProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfObjectKeysProp(options).optional); + expectAssignable>( + oneOfObjectKeysProp(options).optional, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfObjectKeysProp(options).optional); + expectAssignable>( + oneOfObjectKeysProp(options).optional, + ); }); }); describe('oneOfObjectKeysProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfObjectKeysProp(options).nullable); + expectAssignable>( + oneOfObjectKeysProp(options).nullable, + ); expectType>( createVue2Component(oneOfObjectKeysProp(options).nullable), @@ -37,17 +45,23 @@ describe('oneOfObjectKeysProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfObjectKeysProp(options).nullable); + expectAssignable>( + oneOfObjectKeysProp(options).nullable, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfObjectKeysProp(options).nullable); + expectAssignable>( + oneOfObjectKeysProp(options).nullable, + ); }); }); describe('oneOfObjectKeysProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfObjectKeysProp(options).withDefault('a')); + expectAssignable>( + oneOfObjectKeysProp(options).withDefault('a'), + ); expectType>( createVue2Component(oneOfObjectKeysProp(options).withDefault('a')), @@ -55,17 +69,23 @@ describe('oneOfObjectKeysProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfObjectKeysProp(options).withDefault('a')); + expectAssignable>( + oneOfObjectKeysProp(options).withDefault('a'), + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfObjectKeysProp(options).withDefault('a')); + expectAssignable>( + oneOfObjectKeysProp(options).withDefault('a'), + ); }); }); describe('oneOfObjectKeysProp().required', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfObjectKeysProp(options).required); + expectAssignable>( + oneOfObjectKeysProp(options).required, + ); expectType>( createVue2Component(oneOfObjectKeysProp(options).required), @@ -73,7 +93,9 @@ describe('oneOfObjectKeysProp().required', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfObjectKeysProp(options).required); + expectAssignable>( + oneOfObjectKeysProp(options).required, + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/oneOfTypes.type.spec.ts b/type-tests/prop-types/oneOfTypes.type.spec.ts index afe3602f..c7c5d0bb 100644 --- a/type-tests/prop-types/oneOfTypes.type.spec.ts +++ b/type-tests/prop-types/oneOfTypes.type.spec.ts @@ -7,11 +7,13 @@ import { createVue2Component } from '../utils'; import type { Vue2ComponentWithProp } from '../utils'; const options = [Number, String]; -type Options = number | string +type Options = number | string; describe('oneOfTypesProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfTypesProp(options).optional); + expectAssignable>( + oneOfTypesProp(options).optional, + ); expectType>( createVue2Component(oneOfTypesProp(options).optional), @@ -19,17 +21,23 @@ describe('oneOfTypesProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfTypesProp(options).optional); + expectAssignable>( + oneOfTypesProp(options).optional, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfTypesProp(options).optional); + expectAssignable>( + oneOfTypesProp(options).optional, + ); }); }); describe('oneOfTypesProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfTypesProp(options).nullable); + expectAssignable>( + oneOfTypesProp(options).nullable, + ); expectType>( createVue2Component(oneOfTypesProp(options).nullable), @@ -37,17 +45,23 @@ describe('oneOfTypesProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfTypesProp(options).nullable); + expectAssignable>( + oneOfTypesProp(options).nullable, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfTypesProp(options).nullable); + expectAssignable>( + oneOfTypesProp(options).nullable, + ); }); }); describe('oneOfTypesProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfTypesProp(options).withDefault('a')); + expectAssignable>( + oneOfTypesProp(options).withDefault('a'), + ); expectType>( createVue2Component(oneOfTypesProp(options).withDefault('a')), @@ -55,17 +69,23 @@ describe('oneOfTypesProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfTypesProp(options).withDefault('a')); + expectAssignable>( + oneOfTypesProp(options).withDefault('a'), + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfTypesProp(options).withDefault('a')); + expectAssignable>( + oneOfTypesProp(options).withDefault('a'), + ); }); }); describe('oneOfTypesProp().required', () => { describe('Vue 2.6', () => { - expectAssignable>(oneOfTypesProp(options).required); + expectAssignable>( + oneOfTypesProp(options).required, + ); expectType>( createVue2Component(oneOfTypesProp(options).required), @@ -73,10 +93,14 @@ describe('oneOfTypesProp().required', () => { }); describe('Vue 2.7', () => { - expectAssignable>(oneOfTypesProp(options).required); + expectAssignable>( + oneOfTypesProp(options).required, + ); }); describe('Vue 3', () => { - expectAssignable>(oneOfTypesProp(options).required); + expectAssignable>( + oneOfTypesProp(options).required, + ); }); }); diff --git a/type-tests/prop-types/string.type.spec.ts b/type-tests/prop-types/string.type.spec.ts index 0d7d3552..5dc96260 100644 --- a/type-tests/prop-types/string.type.spec.ts +++ b/type-tests/prop-types/string.type.spec.ts @@ -10,8 +10,12 @@ type Foo = 'a' | 'b' | 'c'; describe('stringProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(stringProp().optional); - expectAssignable>(stringProp().optional); + expectAssignable>( + stringProp().optional, + ); + expectAssignable>( + stringProp().optional, + ); expectNotAssignable>(stringProp().optional); expectNotAssignable>(stringProp().optional); @@ -25,8 +29,12 @@ describe('stringProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(stringProp().optional); - expectAssignable>(stringProp().optional); + expectAssignable>( + stringProp().optional, + ); + expectAssignable>( + stringProp().optional, + ); expectNotAssignable>(stringProp().optional); expectNotAssignable>(stringProp().optional); }); @@ -42,7 +50,9 @@ describe('stringProp().optional', () => { describe('stringProp().nullable', () => { describe('Vue 2.6', () => { expectAssignable>(stringProp().nullable); - expectAssignable>(stringProp().nullable); + expectAssignable>( + stringProp().nullable, + ); expectNotAssignable>(stringProp().nullable); expectNotAssignable>(stringProp().nullable); @@ -57,7 +67,9 @@ describe('stringProp().nullable', () => { describe('Vue 2.7', () => { expectAssignable>(stringProp().nullable); - expectAssignable>(stringProp().nullable); + expectAssignable>( + stringProp().nullable, + ); expectNotAssignable>(stringProp().nullable); expectNotAssignable>(stringProp().nullable); }); @@ -72,10 +84,18 @@ describe('stringProp().nullable', () => { describe('stringProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(stringProp().withDefault('foo')); - expectAssignable>(stringProp().withDefault('a')); - expectNotAssignable>(stringProp().withDefault('foo')); - expectNotAssignable>(stringProp().withDefault('a')); + expectAssignable>( + stringProp().withDefault('foo'), + ); + expectAssignable>( + stringProp().withDefault('a'), + ); + expectNotAssignable>( + stringProp().withDefault('foo'), + ); + expectNotAssignable>( + stringProp().withDefault('a'), + ); expectType>( createVue2Component(stringProp().withDefault('foo')), @@ -87,10 +107,18 @@ describe('stringProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(stringProp().withDefault('foo')); - expectAssignable>(stringProp().withDefault('a')); - expectNotAssignable>(stringProp().withDefault('foo')); - expectNotAssignable>(stringProp().withDefault('a')); + expectAssignable>( + stringProp().withDefault('foo'), + ); + expectAssignable>( + stringProp().withDefault('a'), + ); + expectNotAssignable>( + stringProp().withDefault('foo'), + ); + expectNotAssignable>( + stringProp().withDefault('a'), + ); }); describe('Vue 3', () => { diff --git a/type-tests/prop-types/symbol.type.spec.ts b/type-tests/prop-types/symbol.type.spec.ts index b4591f32..876f3535 100644 --- a/type-tests/prop-types/symbol.type.spec.ts +++ b/type-tests/prop-types/symbol.type.spec.ts @@ -8,7 +8,9 @@ import type { Vue2ComponentWithProp } from '../utils'; describe('symbolProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(symbolProp().optional); + expectAssignable>( + symbolProp().optional, + ); expectNotAssignable>(symbolProp().optional); expectType>( @@ -17,7 +19,9 @@ describe('symbolProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(symbolProp().optional); + expectAssignable>( + symbolProp().optional, + ); expectNotAssignable>(symbolProp().optional); }); @@ -50,8 +54,12 @@ describe('symbolProp().nullable', () => { describe('symbolProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(symbolProp().withDefault(Symbol.for('foo'))); - expectNotAssignable>(symbolProp().withDefault(Symbol.for('foo'))); + expectAssignable>( + symbolProp().withDefault(Symbol.for('foo')), + ); + expectNotAssignable>( + symbolProp().withDefault(Symbol.for('foo')), + ); expectType>( createVue2Component(symbolProp().withDefault(Symbol.for('foo'))), @@ -59,13 +67,21 @@ describe('symbolProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(symbolProp().withDefault(Symbol.for('foo'))); - expectNotAssignable>(symbolProp().withDefault(Symbol.for('foo'))); + expectAssignable>( + symbolProp().withDefault(Symbol.for('foo')), + ); + expectNotAssignable>( + symbolProp().withDefault(Symbol.for('foo')), + ); }); describe('Vue 3', () => { - expectAssignable>(symbolProp().withDefault(Symbol.for('foo'))); - expectNotAssignable>(symbolProp().withDefault(Symbol.for('foo'))); + expectAssignable>( + symbolProp().withDefault(Symbol.for('foo')), + ); + expectNotAssignable>( + symbolProp().withDefault(Symbol.for('foo')), + ); }); }); diff --git a/type-tests/prop-types/vueComponent.type.spec.ts b/type-tests/prop-types/vueComponent.type.spec.ts index f9e13c1f..c8e2ad4a 100644 --- a/type-tests/prop-types/vueComponent.type.spec.ts +++ b/type-tests/prop-types/vueComponent.type.spec.ts @@ -9,8 +9,12 @@ import type { Vue2ComponentWithProp } from '../utils'; describe('vueComponentProp().optional', () => { describe('Vue 2.6', () => { - expectAssignable>(vueComponentProp().optional); - expectNotAssignable>(vueComponentProp().optional); + expectAssignable>( + vueComponentProp().optional, + ); + expectNotAssignable>( + vueComponentProp().optional, + ); expectType>( createVue2Component(vueComponentProp().optional), @@ -18,20 +22,30 @@ describe('vueComponentProp().optional', () => { }); describe('Vue 2.7', () => { - expectAssignable>(vueComponentProp().optional); - expectNotAssignable>(vueComponentProp().optional); + expectAssignable>( + vueComponentProp().optional, + ); + expectNotAssignable>( + vueComponentProp().optional, + ); }); describe('Vue 3', () => { - expectAssignable>(vueComponentProp().optional); + expectAssignable>( + vueComponentProp().optional, + ); expectNotAssignable>(vueComponentProp().optional); }); }); describe('vueComponentProp().nullable', () => { describe('Vue 2.6', () => { - expectAssignable>(vueComponentProp().nullable); - expectNotAssignable>(vueComponentProp().nullable); + expectAssignable>( + vueComponentProp().nullable, + ); + expectNotAssignable>( + vueComponentProp().nullable, + ); expectType>( createVue2Component(vueComponentProp().nullable), @@ -39,20 +53,30 @@ describe('vueComponentProp().nullable', () => { }); describe('Vue 2.7', () => { - expectAssignable>(vueComponentProp().nullable); - expectNotAssignable>(vueComponentProp().nullable); + expectAssignable>( + vueComponentProp().nullable, + ); + expectNotAssignable>( + vueComponentProp().nullable, + ); }); describe('Vue 3', () => { - expectAssignable>(vueComponentProp().nullable); + expectAssignable>( + vueComponentProp().nullable, + ); expectNotAssignable>(vueComponentProp().nullable); }); }); describe('vueComponentProp().withDefault', () => { describe('Vue 2.6', () => { - expectAssignable>(vueComponentProp().withDefault('foo')); - expectNotAssignable>(vueComponentProp().withDefault('foo')); + expectAssignable>( + vueComponentProp().withDefault('foo'), + ); + expectNotAssignable>( + vueComponentProp().withDefault('foo'), + ); expectType>( createVue2Component(vueComponentProp().withDefault('foo')), @@ -60,20 +84,32 @@ describe('vueComponentProp().withDefault', () => { }); describe('Vue 2.7', () => { - expectAssignable>(vueComponentProp().withDefault('foo')); - expectNotAssignable>(vueComponentProp().withDefault('foo')); + expectAssignable>( + vueComponentProp().withDefault('foo'), + ); + expectNotAssignable>( + vueComponentProp().withDefault('foo'), + ); }); describe('Vue 3', () => { - expectAssignable>(vueComponentProp().withDefault('foo')); - expectNotAssignable>(vueComponentProp().withDefault('foo')); + expectAssignable>( + vueComponentProp().withDefault('foo'), + ); + expectNotAssignable>( + vueComponentProp().withDefault('foo'), + ); }); }); describe('vueComponentProp().required', () => { describe('Vue 2.6', () => { - expectAssignable>(vueComponentProp().required); - expectNotAssignable>(vueComponentProp().required); + expectAssignable>( + vueComponentProp().required, + ); + expectNotAssignable>( + vueComponentProp().required, + ); expectType>( createVue2Component(vueComponentProp().required), @@ -81,8 +117,12 @@ describe('vueComponentProp().required', () => { }); describe('Vue 2.7', () => { - expectAssignable>(vueComponentProp().required); - expectNotAssignable>(vueComponentProp().required); + expectAssignable>( + vueComponentProp().required, + ); + expectNotAssignable>( + vueComponentProp().required, + ); }); describe('Vue 3', () => { diff --git a/type-tests/utils.ts b/type-tests/utils.ts index 1cc96930..c04cb19f 100644 --- a/type-tests/utils.ts +++ b/type-tests/utils.ts @@ -3,8 +3,15 @@ import type { PropOptions } from 'vue2-6/types/options'; import type { ExtendedVue } from 'vue2-6/types/vue'; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const createVue2Component = (prop: T) => Vue.component('test', { - props: { prop }, -}); +export const createVue2Component = (prop: T) => + Vue.component('test', { + props: { prop }, + }); -export type Vue2ComponentWithProp = ExtendedVue +export type Vue2ComponentWithProp = ExtendedVue< + Vue, + unknown, + unknown, + unknown, + { prop: T } +>; From 6f426829adbe6bfe65de6cb3484087b6a7f892a1 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Mon, 18 Sep 2023 17:09:20 +0200 Subject: [PATCH 5/5] Don't use deprecated ts-jest type --- jest.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 71752a20..3ef9b0b9 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,6 +1,6 @@ -import type { InitialOptionsTsJest } from 'ts-jest/dist/types'; +import type { JestConfigWithTsJest } from 'ts-jest'; -const config: InitialOptionsTsJest = { +const config: JestConfigWithTsJest = { clearMocks: true, preset: 'ts-jest', transform: {