├── .eslintrc.js ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── jest.config.js ├── package-lock.json ├── package.json ├── src ├── as-safely.test.ts ├── as-safely.ts └── index.ts └── tsconfig.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | node: true, 5 | es2020: true, 6 | jest: true, 7 | }, 8 | extends: [ 9 | 'eslint:recommended', 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:@typescript-eslint/eslint-recommended', 12 | 'plugin:import/errors', 13 | 'plugin:import/warnings', 14 | 'plugin:import/typescript', 15 | 'prettier', 16 | ], 17 | parser: '@typescript-eslint/parser', 18 | parserOptions: { 19 | sourceType: 'module', 20 | }, 21 | plugins: ['@typescript-eslint'], 22 | rules: { 23 | '@typescript-eslint/no-empty-function': 0, 24 | '@typescript-eslint/no-empty-interface': 0, 25 | 'react/prop-types': 0, 26 | 'sort-imports': 0, 27 | 'import/no-unresolved': 0, 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Example user template template 2 | ### Example user template 3 | 4 | # IntelliJ project files 5 | .idea 6 | *.iml 7 | out 8 | gen 9 | ### Node template 10 | # Logs 11 | logs 12 | *.log 13 | npm-debug.log* 14 | yarn-debug.log* 15 | yarn-error.log* 16 | lerna-debug.log* 17 | 18 | # Diagnostic reports (https://nodejs.org/api/report.html) 19 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 20 | 21 | # Runtime data 22 | pids 23 | *.pid 24 | *.seed 25 | *.pid.lock 26 | 27 | # Directory for instrumented libs generated by jscoverage/JSCover 28 | lib-cov 29 | 30 | # Coverage directory used by tools like istanbul 31 | coverage 32 | *.lcov 33 | 34 | # nyc test coverage 35 | .nyc_output 36 | 37 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 38 | .grunt 39 | 40 | # Bower dependency directory (https://bower.io/) 41 | bower_components 42 | 43 | # node-waf configuration 44 | .lock-wscript 45 | 46 | # Compiled binary addons (https://nodejs.org/api/addons.html) 47 | build/Release 48 | 49 | # Dependency directories 50 | node_modules/ 51 | jspm_packages/ 52 | 53 | # Snowpack dependency directory (https://snowpack.dev/) 54 | web_modules/ 55 | 56 | # TypeScript cache 57 | *.tsbuildinfo 58 | 59 | # Optional npm cache directory 60 | .npm 61 | 62 | # Optional eslint cache 63 | .eslintcache 64 | 65 | # Microbundle cache 66 | .rpt2_cache/ 67 | .rts2_cache_cjs/ 68 | .rts2_cache_es/ 69 | .rts2_cache_umd/ 70 | 71 | # Optional REPL history 72 | .node_repl_history 73 | 74 | # Output of 'npm pack' 75 | *.tgz 76 | 77 | # Yarn Integrity file 78 | .yarn-integrity 79 | 80 | # dotenv environment variables file 81 | .env 82 | .env.test 83 | 84 | # parcel-bundler cache (https://parceljs.org/) 85 | .cache 86 | .parcel-cache 87 | 88 | # Next.js build output 89 | .next 90 | out 91 | 92 | # Nuxt.js build / generate output 93 | .nuxt 94 | dist 95 | 96 | # Gatsby files 97 | .cache/ 98 | # Comment in the public line in if your project uses Gatsby and not Next.js 99 | # https://nextjs.org/blog/next-9-1#public-directory-support 100 | # public 101 | 102 | # vuepress build output 103 | .vuepress/dist 104 | 105 | # Serverless directories 106 | .serverless/ 107 | 108 | # FuseBox cache 109 | .fusebox/ 110 | 111 | # DynamoDB Local files 112 | .dynamodb/ 113 | 114 | # TernJS port file 115 | .tern-port 116 | 117 | # Stores VSCode versions used for testing VSCode extensions 118 | .vscode-test 119 | 120 | # yarn v2 121 | .yarn/cache 122 | .yarn/unplugged 123 | .yarn/build-state.yml 124 | .yarn/install-state.gz 125 | .pnp.* 126 | 127 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | .idea/ 3 | node_modules/ 4 | .gitignore 5 | .eslintrc.js 6 | jest.config.js 7 | package-lock.json 8 | tsconfig.json 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-present Yuito Sato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # as-safely 2 | A library for safe type assertion in TypeScript. 3 | 4 | The function asSafely throws an exception if it fails to check the type at runtime. This function will also perform type checking when transpiling to JavaScript whenever possible. 5 | 6 | With this library, you can eliminate dangerous Type Assertions in your project. 7 | 8 | # Install 9 | ``` 10 | npm install as-safely 11 | ``` 12 | 13 | # Quickstart 14 | 15 | ```ts 16 | import { asSafely, isString, isArray, isNumber } from './as-safely'; 17 | 18 | const str1: string = asSafely('1' as unknown, isString); 19 | // => OK 20 | 21 | const strOrUndefined: string | undefined = asSafely(undefined as unknown, [isString, isUndefined]); 22 | // => OK 23 | 24 | const numberArray: number[] = asSafely([1, 2] as unknown, isArray(isNumber)); 25 | // => OK 26 | 27 | const str2: string = asSafely(1, isString); 28 | // => detects a transpile error. 29 | 30 | const str3: string = asSafely(1 as unknown, isString); 31 | // => throws a runtime error. 32 | 33 | const str4: string = asSafely(1, isString); 34 | // => forces to predict an object as string. This will throw a runtime error. 35 | 36 | const strOrUndefined2: string | undefined = asSafely(1 as unknown, isString, () => undefined); 37 | // => not throws a runtime error and returns undefined. 38 | 39 | const strWithCustomError: string = asSafely(1 as unknown, isString, (obj) => { 40 | console.error(obj); 41 | throw new Error('custom error') 42 | }); 43 | // => throws a custom error. 44 | ``` 45 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/src'], 3 | transform: { 4 | '^.+\\.tsx?$': 'ts-jest', 5 | }, 6 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', 7 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 8 | }; 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "as-safely", 3 | "version": "0.1.3", 4 | "description": "TypeScript Library for safe type assertion", 5 | "main": "./dist/index.js", 6 | "typings": "dist/index.d.ts", 7 | "scripts": { 8 | "build": "tsc", 9 | "test": "jest", 10 | "prettier": "prettier --write 'src/**/*.{ts,tsx,css}' --loglevel warn", 11 | "lint": "eslint './src/**/*.ts'" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/YuitoSato/as-safely.git" 16 | }, 17 | "keywords": [ 18 | "javascript", 19 | "typescript", 20 | "typechecker", 21 | "check-type", 22 | "javascript-type", 23 | "primitive-types", 24 | "plain-object", 25 | "plain-objects", 26 | "class-instance", 27 | "class-identifier", 28 | "type-checking", 29 | "type-checker", 30 | "type-check", 31 | "define-type", 32 | "get-type", 33 | "what-type", 34 | "is-object", 35 | "is-plain-obj", 36 | "is-plain-object", 37 | "type-assertion" 38 | ], 39 | "author": "YuitoSato", 40 | "license": "MIT", 41 | "bugs": { 42 | "url": "https://github.com/YuitoSato/as-safely/issues" 43 | }, 44 | "prettier": { 45 | "printWidth": 100, 46 | "singleQuote": true 47 | }, 48 | "lint-staged": { 49 | "*.{ts,tsx,css}": [ 50 | "eslint --fix", 51 | "prettier --write --loglevel warn" 52 | ] 53 | }, 54 | "homepage": "https://github.com/YuitoSato/as-safely#readme", 55 | "devDependencies": { 56 | "@types/jest": "^27.0.1", 57 | "@typescript-eslint/eslint-plugin": "^4.30.0", 58 | "@typescript-eslint/parser": "^4.30.0", 59 | "eslint": "^7.32.0", 60 | "eslint-config-prettier": "^8.3.0", 61 | "eslint-plugin-import": "^2.24.2", 62 | "jest": "^27.1.0", 63 | "lint-staged": "^11.1.2", 64 | "prettier": "^2.3.2", 65 | "ts-jest": "^27.0.5", 66 | "typescript": "^4.4.2" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/as-safely.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | asSafely, 3 | isArray, 4 | isBigint, 5 | isBoolean, 6 | isDate, 7 | isNull, 8 | isNumber, 9 | isString, 10 | isSymbol, 11 | isUndefined, 12 | } from './as-safely'; 13 | 14 | describe('asSafely', () => { 15 | describe('when string is provided', () => { 16 | it('should predict type when type assertion is succeeded', () => { 17 | const unknownStr: unknown = 'str'; 18 | const str: string = asSafely(unknownStr, isString); 19 | expect(str).toStrictEqual(unknownStr); 20 | }); 21 | 22 | it('should predict type when the passed object contains the target type', () => { 23 | const unknownStr: string | number = 'str'; 24 | const str: string = asSafely(unknownStr, isString); 25 | expect(str).toStrictEqual(unknownStr); 26 | }); 27 | 28 | it('should throw an error when type assertion is failed', () => { 29 | const unknownNumber: unknown = 1; 30 | expect(() => asSafely(unknownNumber, isString)).toThrow( 31 | `type assertion is failed. object type: number. object keys: ` 32 | ); 33 | }); 34 | 35 | it('should return undefined when type assertion is failed and orElse returns undefined', () => { 36 | const unknownNumber: unknown = 1; 37 | const strOrUndefined: string | undefined = asSafely(unknownNumber, isString, () => undefined); 38 | expect(strOrUndefined).toStrictEqual(undefined); 39 | }); 40 | }); 41 | 42 | describe('when custom type is provided', () => { 43 | type Hoge = { 44 | str: string; 45 | num: number; 46 | }; 47 | 48 | const isHoge = (obj: unknown): obj is Hoge => { 49 | const hoge = obj as Hoge; 50 | return hoge.str != null && hoge.num != null; 51 | }; 52 | 53 | it('should predict custom type when type assertion is succeeded', () => { 54 | const unknown: unknown = { 55 | str: 'str', 56 | num: 1, 57 | }; 58 | const hoge: Hoge = asSafely(unknown, isHoge); 59 | expect(hoge).toStrictEqual({ 60 | str: 'str', 61 | num: 1, 62 | }); 63 | }); 64 | 65 | it('should throw an error when type assertion is failed', () => { 66 | const unknown: unknown = { 67 | str2: 'str', 68 | num2: 1, 69 | }; 70 | expect(() => asSafely(unknown, isString)).toThrow( 71 | `type assertion is failed. object type: object. object keys: str2,num2` 72 | ); 73 | }); 74 | }); 75 | 76 | describe('when multiple conditions are provided', () => { 77 | it('should predict type when type assertion is succeeded', () => { 78 | const unknownUndefined = undefined as unknown; 79 | expect(asSafely(unknownUndefined, [isString, isUndefined])).toStrictEqual(undefined); 80 | const unknownString = '1' as unknown; 81 | expect(asSafely(unknownString, [isString, isUndefined])).toStrictEqual('1'); 82 | }); 83 | 84 | it('should throw an error when type assertion is failed', () => { 85 | const unknown = 1 as unknown; 86 | expect(() => asSafely(unknown, [isString, isUndefined])).toThrow( 87 | `type assertion is failed. object type: number. object keys: ` 88 | ); 89 | }); 90 | }); 91 | }); 92 | 93 | describe('isString', () => { 94 | test('should return true when string is provided', () => { 95 | const unknown: unknown = 'str'; 96 | expect(isString(unknown)).toStrictEqual(true); 97 | }); 98 | 99 | test('should return false when string is not provided', () => { 100 | const unknown: unknown = 1; 101 | expect(isString(unknown)).toStrictEqual(false); 102 | }); 103 | }); 104 | 105 | describe('isBoolean', () => { 106 | test('should return true when boolean is provided', () => { 107 | const unknown: unknown = true; 108 | expect(isBoolean(unknown)).toStrictEqual(true); 109 | }); 110 | 111 | test('should return false when boolean is not provided', () => { 112 | const unknown: unknown = 1; 113 | expect(isBoolean(unknown)).toStrictEqual(false); 114 | }); 115 | }); 116 | 117 | describe('isNumber', () => { 118 | test('should return true when number is provided', () => { 119 | const unknown: unknown = 1; 120 | expect(isNumber(unknown)).toStrictEqual(true); 121 | }); 122 | 123 | test('should return false when number is not provided', () => { 124 | const unknown: unknown = '1'; 125 | expect(isNumber(unknown)).toStrictEqual(false); 126 | }); 127 | }); 128 | 129 | describe('isSymbol', () => { 130 | test('should return true when symbol is provided', () => { 131 | const unknown: unknown = Symbol(1); 132 | expect(isSymbol(unknown)).toStrictEqual(true); 133 | }); 134 | 135 | test('should return false when symbol is not provided', () => { 136 | const unknown: unknown = 1; 137 | expect(isSymbol(unknown)).toStrictEqual(false); 138 | }); 139 | }); 140 | 141 | describe('isBigint', () => { 142 | test('should return true when bigint is provided', () => { 143 | const unknown: unknown = BigInt('1'); 144 | expect(isBigint(unknown)).toStrictEqual(true); 145 | }); 146 | 147 | test('should return false when bigint is not provided', () => { 148 | const unknown: unknown = 1; 149 | expect(isBigint(unknown)).toStrictEqual(false); 150 | }); 151 | }); 152 | 153 | describe('isUndefined', () => { 154 | test('should return true when undefined is provided', () => { 155 | const unknown: unknown = undefined; 156 | expect(isUndefined(unknown)).toStrictEqual(true); 157 | }); 158 | 159 | test('should return false when undefined is not provided', () => { 160 | const unknown: unknown = '1'; 161 | expect(isUndefined(unknown)).toStrictEqual(false); 162 | }); 163 | }); 164 | 165 | describe('isNull', () => { 166 | test('should return true when null is provided', () => { 167 | const unknown: unknown = null; 168 | expect(isNull(unknown)).toStrictEqual(true); 169 | }); 170 | 171 | test('should return false when null is not provided', () => { 172 | const unknown: unknown = '1'; 173 | expect(isNull(unknown)).toStrictEqual(false); 174 | }); 175 | }); 176 | 177 | describe('isDate', () => { 178 | test('should return true when date is provided', () => { 179 | const unknown: unknown = new Date(2021, 1, 1); 180 | expect(isDate(unknown)).toStrictEqual(true); 181 | }); 182 | 183 | test('should return false when date is not provided', () => { 184 | const unknown: unknown = 1; 185 | expect(isDate(unknown)).toStrictEqual(false); 186 | }); 187 | 188 | test('should return false when invalid date is provided', () => { 189 | const unknown: unknown = new Date('test'); 190 | expect(isDate(unknown)).toStrictEqual(false); 191 | }); 192 | }); 193 | 194 | describe('isArray', () => { 195 | test('should return true when string array is provided', () => { 196 | const unknown: unknown = ['a', 'b']; 197 | expect(isArray(isString)(unknown)).toStrictEqual(true); 198 | }); 199 | 200 | test('should return true when empty array is provided', () => { 201 | const unknown: unknown = []; 202 | expect(isArray(isString)(unknown)).toStrictEqual(true); 203 | }); 204 | 205 | test('should return false when string array is not provided', () => { 206 | const unknown: unknown = ['a', 1]; 207 | expect(isArray(isString)(unknown)).toStrictEqual(false); 208 | }); 209 | }); 210 | -------------------------------------------------------------------------------- /src/as-safely.ts: -------------------------------------------------------------------------------- 1 | const asSafely = ( 2 | obj: TARGET, 3 | condition: 4 | | ((obj: unknown) => obj is RESULT) 5 | | [(obj: unknown) => obj is RESULT, (obj: unknown) => obj is RESULT2], 6 | // eslint-disable-next-line no-unused-vars 7 | orElse?: (obj: TARGET) => OR_ELSE 8 | ): RESULT | RESULT2 | OR_ELSE => { 9 | if (!Array.isArray(condition) && condition(obj)) { 10 | return obj as RESULT; 11 | } 12 | if (Array.isArray(condition) && condition.length > 0 && condition.some((c) => c(obj))) { 13 | return obj as RESULT | RESULT2; 14 | } 15 | if (orElse != null) { 16 | return orElse(obj); 17 | } 18 | throw new Error( 19 | `type assertion is failed. object type: ${typeof obj}. object keys: ${obj && Object.keys(obj)}` 20 | ); 21 | }; 22 | 23 | const isString = (obj: unknown): obj is string => typeof obj === 'string'; 24 | const isBoolean = (obj: unknown): obj is boolean => typeof obj === 'boolean'; 25 | const isNumber = (obj: unknown): obj is number => typeof obj === 'number'; 26 | const isSymbol = (obj: unknown): obj is symbol => typeof obj === 'symbol'; 27 | const isBigint = (obj: unknown): obj is bigint => typeof obj === 'bigint'; 28 | const isUndefined = (obj: unknown): obj is undefined => typeof obj === 'undefined'; 29 | const isNull = (obj: unknown): obj is null => obj === null; 30 | const isDate = (obj: unknown): obj is Date => obj instanceof Date && !isNaN(obj.getTime()); 31 | const isArray = (elementCondition: (element: unknown) => element is ELEMENT) => { 32 | return (obj: unknown): obj is ELEMENT[] => Array.isArray(obj) && obj.every(elementCondition); 33 | }; 34 | 35 | export { 36 | asSafely, 37 | isString, 38 | isBoolean, 39 | isNumber, 40 | isSymbol, 41 | isBigint, 42 | isUndefined, 43 | isNull, 44 | isDate, 45 | isArray, 46 | }; 47 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './as-safely'; 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "ES2019", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 22 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | 26 | /* Modules */ 27 | "module": "commonjs", /* Specify what module code is generated. */ 28 | // "rootDir": "./", /* Specify the root folder within your source files. */ 29 | // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 30 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 31 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 32 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 33 | // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ 34 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 35 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 36 | // "resolveJsonModule": true, /* Enable importing .json files */ 37 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 38 | 39 | /* JavaScript Support */ 40 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ 41 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 42 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 43 | 44 | /* Emit */ 45 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 46 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 47 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 48 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 49 | // "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. */ 50 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 51 | // "removeComments": true, /* Disable emitting comments. */ 52 | // "noEmit": true, /* Disable emitting files from a compilation. */ 53 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 54 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 55 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 56 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 59 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 60 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 61 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 62 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 63 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 64 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 65 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 66 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 67 | 68 | /* Interop Constraints */ 69 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 70 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 71 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ 72 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 73 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 74 | 75 | /* Type Checking */ 76 | "strict": true, /* Enable all strict type-checking options. */ 77 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 78 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 79 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 80 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 81 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 82 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 83 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 84 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 85 | // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ 86 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ 87 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 88 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 89 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 90 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 91 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 92 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 93 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 94 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 95 | 96 | /* Completeness */ 97 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 98 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 99 | }, 100 | "include": [ 101 | "src/**/*.ts" 102 | ], 103 | "exclude": ["src/**/*.test.ts"], 104 | } 105 | --------------------------------------------------------------------------------