├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── dist ├── ts-object-transformer.d.ts └── ts-object-transformer.js ├── package-lock.json ├── package.json ├── src ├── ts-object-transformer.spec.ts └── ts-object-transformer.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Specificities 2 | # Removing spec files from dist folder 3 | # Another option would be exclude spec files in tsconfig, but for strange reason, 4 | # spec files doesn't compile well after that 5 | dist/**/*.spec.* 6 | 7 | # Intellij IDEA 8 | *.iml 9 | 10 | # Logs 11 | logs 12 | *.log 13 | npm-debug.log* 14 | yarn-debug.log* 15 | yarn-error.log* 16 | 17 | # Runtime data 18 | pids 19 | *.pid 20 | *.seed 21 | *.pid.lock 22 | 23 | # Directory for instrumented libs generated by jscoverage/JSCover 24 | lib-cov 25 | 26 | # Coverage directory used by tools like istanbul 27 | coverage 28 | 29 | # nyc test coverage 30 | .nyc_output 31 | 32 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Bower dependency directory (https://bower.io/) 36 | bower_components 37 | 38 | # node-waf configuration 39 | .lock-wscript 40 | 41 | # Compiled binary addons (https://nodejs.org/api/addons.html) 42 | build/Release 43 | 44 | # Dependency directories 45 | node_modules/ 46 | jspm_packages/ 47 | 48 | # TypeScript v1 declaration files 49 | typings/ 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional REPL history 58 | .node_repl_history 59 | 60 | # Output of 'npm pack' 61 | *.tgz 62 | 63 | # Yarn Integrity file 64 | .yarn-integrity 65 | 66 | # dotenv environment variables file 67 | .env 68 | 69 | # next.js build output 70 | .next 71 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '9.10.1' 4 | before_install: 5 | - npm install 6 | script: 7 | - npm test 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Frédéric Camblor 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 | # ts-object-transformer [![Build Status](https://travis-ci.org/fcamblor/ts-object-transformer.svg?branch=master)](https://travis-ci.org/fcamblor/ts-object-transformer) 2 | 3 | > Typescript Type-safe object transformation, with no magic (no decorators, no typescript compilation plugins) 4 | 5 | Useful for JSON mappings with complex JS/TS types (Date, Regex etc.) 6 | 7 | ## Requirements 8 | 9 | Typescript >= 2.8 10 | 11 | ## Install 12 | 13 | ``` 14 | $ npm install ts-object-transformer 15 | ``` 16 | 17 | ## API 18 | 19 | ```ts 20 | transformObject( 21 | // Standard plain object literal coming, most of the time from serverside, 22 | // generally described by an interface 23 | objectLiteral, 24 | // Applying some mapping aimed at converting input values above and change their type representation 25 | // Rules are : 26 | // - Keys should be a subset of objectLiteral's keys; Omitting key will not make any field transformation. 27 | // - Values should be a function taking objectLiteral[key] and returning a transformed value 28 | // If you're not following these rules, there will be a compilation error 29 | fieldMappings?, 30 | // Aimed at generating new "computed" properties 31 | // Rules are : 32 | // - Keys *cannot* be one of objectLiteral's keys 33 | // - Values should be a function taking objectLiteral[key] and returning a tranformed value 34 | // If you're not following these rules, there will be a compilation error 35 | computedMappings? 36 | ); 37 | // Returns a result having : 38 | // - Same keys than objectLiteral 39 | // - Types of these keys potentially translated using fieldMappings' transformations return types 40 | // - New keys corresponding to computedMappings' keys & transformations return types 41 | ``` 42 | 43 | ## Usage 44 | 45 | ```ts 46 | import {transformObject} from 'ts-object-transformer'; 47 | 48 | let transformedResult = transformObject( 49 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 50 | { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape }, 51 | { year: (obj) => obj.date.substr(0, 4) } 52 | ); 53 | 54 | // Doesn't compile : Argument of type "blah" doesn't exist on type 55 | // let blah = transformedResult.blah; 56 | 57 | // Doesn't compile : "type 'Date' is not assignable to type 'number'" 58 | // Proves that date2 has been converted to Date 59 | // let num: number = transformedResult.date2; 60 | 61 | console.log(transformedResult.date); // 1538604000000 62 | console.log(transformedResult.date2); // 2018-10-03T22:00:00.000Z (new Date(1538604000000)) 63 | console.log(transformedResult.aString); // Hello world 64 | console.log(transformedResult.idempotentValue); // foo 65 | console.log(transformedResult.year); // 2018 66 | ``` 67 | 68 | You can omit either fieldMappings or computedMappings (or both, but it's useless :-) : 69 | 70 | ```ts 71 | let transformedResult2 = transformObject( 72 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 73 | { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape } 74 | ); 75 | 76 | console.log(transformedResult2.date); // 1538604000000 77 | console.log(transformedResult2.date2); // 2018-10-03T22:00:00.000Z (new Date(1538604000000)) 78 | console.log(transformedResult2.aString); // Hello world 79 | console.log(transformedResult2.idempotentValue); // foo 80 | 81 | let transformedResult3 = transformObject( 82 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 83 | undefined, 84 | { year: (obj) => obj.date.substr(0, 4) } 85 | ); 86 | console.log(transformedResult3.date); // 2018-10-04T00:00:00+0200 87 | console.log(transformedResult3.date2); // 1538604000000 88 | console.log(transformedResult3.aString); // Hello%20world 89 | console.log(transformedResult3.idempotentValue); // foo 90 | console.log(transformedResult3.year); // 2018 91 | ``` 92 | 93 | ## License 94 | 95 | MIT -------------------------------------------------------------------------------- /dist/ts-object-transformer.d.ts: -------------------------------------------------------------------------------- 1 | declare type FieldMap = { 2 | [ATTR in keyof SRC]?: (value: SRC[ATTR], obj?: SRC) => any; 3 | }; 4 | declare type ComputedMap = { 5 | [ATTR in keyof SRC]?: never; 6 | } & { 7 | [ATTR: string]: (obj: SRC) => any; 8 | }; 9 | declare type MappedReturnType | undefined, CM extends ComputedMap | undefined> = (CM extends ComputedMap ? { 10 | [ATTR in keyof CM]: ReturnType; 11 | } : unknown) & { 12 | [ATTR in keyof SRC]: ATTR extends keyof FM ? FM[ATTR] extends (value: SRC[ATTR], obj?: SRC) => infer R ? R : SRC[ATTR] : SRC[ATTR]; 13 | }; 14 | export declare function transformObject | undefined, CM extends ComputedMap | undefined>(src: SRC, fieldMap?: FM, computedMap?: CM): MappedReturnType; 15 | export {}; 16 | -------------------------------------------------------------------------------- /dist/ts-object-transformer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function transformObject(src, fieldMap, computedMap) { 4 | let result = {}; 5 | for (let key in src) { 6 | let value = src[key]; 7 | let transformedValue; 8 | if (fieldMap && (key in fieldMap)) { 9 | let transformer = fieldMap[key]; 10 | if (transformer) { 11 | transformedValue = transformer(value, src); 12 | } 13 | else { 14 | transformedValue = value; 15 | } 16 | } 17 | else { 18 | transformedValue = value; 19 | } 20 | result[key] = transformedValue; 21 | } 22 | if (computedMap) { 23 | for (let key in computedMap) { 24 | let transformer = computedMap[key]; 25 | result[key] = transformer(src); 26 | } 27 | } 28 | return result; 29 | } 30 | exports.transformObject = transformObject; 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-object-transformer", 3 | "version": "0.0.2", 4 | "description": "", 5 | "main": "./dist/ts-object-transformer.js", 6 | "typings": "./dist/ts-object-transformer.d.ts", 7 | "scripts": { 8 | "prepare": "npm run build", 9 | "build": "tsc", 10 | "watch": "tsc -w", 11 | "test": "jest" 12 | }, 13 | "author": "fcamblor ", 14 | "license": "MIT", 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/fcamblor/ts-object-transformer.git" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/fcamblor/ts-object-transformer/issues" 21 | }, 22 | "devDependencies": { 23 | "@types/jest": "23.3.2", 24 | "jest": "23.6.0", 25 | "ts-jest": "23.10.3", 26 | "typescript": "3.1.1" 27 | }, 28 | "files": [ 29 | "dist" 30 | ], 31 | "jest": { 32 | "transform": { 33 | "^.+\\.tsx?$": "ts-jest" 34 | }, 35 | "moduleFileExtensions": [ 36 | "ts", 37 | "js" 38 | ], 39 | "testRegex": "^.+\\.spec\\.ts$" 40 | }, 41 | "dependencies": {} 42 | } 43 | -------------------------------------------------------------------------------- /src/ts-object-transformer.spec.ts: -------------------------------------------------------------------------------- 1 | import {transformObject} from './ts-object-transformer'; 2 | 3 | describe("ts-object-transformer", () => { 4 | it("object transformation", () => { 5 | let transformedResult = transformObject( 6 | // Standard plain object literal coming, most of the time from serverside, generally described by an interface 7 | // Let's call this type SRC 8 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 9 | // Applying some mapping aimed at converting input values above and change their type representation 10 | // Rules are : 11 | // - Keys should be a subset of SRC's keys 12 | // - Values should be function taking SRC[key] and returning a new type NEW_TYPE[key] we want to capture in 13 | // order to reference it in transformObject()'s result type 14 | // Let's call this type FIELD_MAP 15 | { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape }, 16 | // Generating new "computed" properties 17 | // Rules are : 18 | // - Keys cannot be one of SRC key 19 | // - Values should be function taking SRC[key] and returning a new type NEW_TYPE[key] we want to capture in 20 | // order to reference it in transformObject()'s result type 21 | // Let's call this type COMPUTED_MAP 22 | { year: (obj) => obj.date.substr(0, 4), strlen: (obj) => obj.aString.length } 23 | ); 24 | // Result type (NEW_TYPE) should be a map with its keys being the union of SRC keys and COMPUTED_MAP keys with following rules : 25 | // - If key exists only in SRC, then NEW_TYPE[key] = SRC[key] 26 | // - If key is a computed key (belonging to COMPUTED_MAP), then NEW_TYPE[key] = ResultType 27 | // - Otherwise (key existing in FIELD_MAP), then NEW_TYPE[key] = ResultType 28 | // In this example, expecting 29 | // mappedResult = { date: Date.parse("2018-10-04T00:00:00+0200"), date2: new Date(1538604000000), aString: unescape("Hello%20World"), idempotentValue: "foo", year: "2018", strlen: 13 } 30 | // .. meaning that expected type would be { date: number, date2: Date, aString: string, idempotentValue: string, year: string, strlen: number } 31 | 32 | expect(Object.keys(transformedResult)).toEqual(['date', 'date2', 'aString', 'idempotentValue', 'year', 'strlen']); 33 | 34 | let v1: number = transformedResult.date; // number, expected 35 | expect(typeof v1).toEqual('number'); 36 | expect(v1).toEqual(1538604000000); 37 | let v2: Date = transformedResult.date2; // Date, expected 38 | expect(typeof v2).toEqual('object'); 39 | expect(v2).toBeInstanceOf(Date); 40 | expect(v2.getTime()).toEqual(1538604000000); 41 | let v3: string = transformedResult.aString; // string, expected 42 | expect(typeof v3).toEqual('string'); 43 | expect(v3).toEqual('Hello World'); 44 | let v4: string = transformedResult.idempotentValue; // string, expected 45 | expect(typeof v4).toEqual('string'); 46 | expect(v4).toEqual('foo'); 47 | let v5: string = transformedResult.year; // string, expected 48 | expect(typeof v5).toEqual('string'); 49 | expect(v5).toEqual('2018'); 50 | let v6: number = transformedResult.strlen; // number, expected 51 | expect(typeof v6).toEqual('number'); 52 | expect(v6).toEqual(13); 53 | 54 | // transformedResult.blah // doesn't compile, Property 'blah' doesn't exist on type 55 | }); 56 | 57 | it("object transformation with no computed values", () => { 58 | let transformedResult = transformObject( 59 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 60 | { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape } 61 | ); 62 | 63 | expect(Object.keys(transformedResult)).toEqual(['date', 'date2', 'aString', 'idempotentValue']); 64 | 65 | let v1: number = transformedResult.date; // number, expected 66 | expect(typeof v1).toEqual('number'); 67 | expect(v1).toEqual(1538604000000); 68 | let v2: Date = transformedResult.date2; // Date, expected 69 | expect(typeof v2).toEqual('object'); 70 | expect(v2).toBeInstanceOf(Date); 71 | expect(v2.getTime()).toEqual(1538604000000); 72 | let v3: string = transformedResult.aString; // string, expected 73 | expect(typeof v3).toEqual('string'); 74 | expect(v3).toEqual('Hello World'); 75 | let v4: string = transformedResult.idempotentValue; // string, expected 76 | expect(typeof v4).toEqual('string'); 77 | expect(v4).toEqual('foo'); 78 | // let v5: string = transformedResult.year; // doesn't compile, property 'year' doesn't exist on type 79 | }); 80 | 81 | function jsonMappingsWithFieldMappings(fieldMapping: {}|undefined) { 82 | let transformedResult = transformObject( 83 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 84 | fieldMapping, 85 | { year: (obj) => obj.date.substr(0, 4) } 86 | ); 87 | 88 | expect(Object.keys(transformedResult)).toEqual(['date', 'date2', 'aString', 'idempotentValue', 'year']); 89 | 90 | let v1: string = transformedResult.date; // string expected 91 | expect(typeof v1).toEqual('string'); 92 | expect(v1).toEqual('2018-10-04T00:00:00+0200'); 93 | let v2: number = transformedResult.date2; // number, expected 94 | expect(typeof v2).toEqual('number'); 95 | expect(v2).toEqual(1538604000000); 96 | let v3: string = transformedResult.aString; // string, expected 97 | expect(typeof v3).toEqual('string'); 98 | expect(v3).toEqual('Hello%20World'); 99 | let v4: string = transformedResult.idempotentValue; // string, expected 100 | expect(typeof v4).toEqual('string'); 101 | expect(v4).toEqual('foo'); 102 | let v5: string = transformedResult.year; // string, expected 103 | expect(typeof v5).toEqual('string'); 104 | expect(v5).toEqual('2018'); 105 | } 106 | it("object transformation with no field mappings", () => { 107 | jsonMappingsWithFieldMappings({}); 108 | }); 109 | 110 | it("object transformation with undefined field mappings", () => { 111 | jsonMappingsWithFieldMappings(undefined); 112 | }); 113 | 114 | it("idempotent transformation", () => { 115 | let transformedResult = transformObject( 116 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" } 117 | ); 118 | 119 | expect(Object.keys(transformedResult)).toEqual(['date', 'date2', 'aString', 'idempotentValue']); 120 | 121 | let v1: string = transformedResult.date; // string expected 122 | expect(typeof v1).toEqual('string'); 123 | expect(v1).toEqual('2018-10-04T00:00:00+0200'); 124 | let v2: number = transformedResult.date2; // number, expected 125 | expect(typeof v2).toEqual('number'); 126 | expect(v2).toEqual(1538604000000); 127 | let v3: string = transformedResult.aString; // string, expected 128 | expect(typeof v3).toEqual('string'); 129 | expect(v3).toEqual('Hello%20World'); 130 | let v4: string = transformedResult.idempotentValue; // string, expected 131 | expect(typeof v4).toEqual('string'); 132 | expect(v4).toEqual('foo'); 133 | // let v5: string = transformedResult.year; // doesn't compile, property 'year' doesn't exist on type 134 | }); 135 | 136 | interface NestedNode { 137 | str: string; 138 | num: number; 139 | } 140 | 141 | it("nested properties", () => { 142 | let transformedResult = transformObject( 143 | { nestedIdemPotent: { str: "foo", num: 123}, nestedChanged: { str: "foo", num: 123 } }, 144 | { nestedChanged: (node: NestedNode) => transformObject(node, { str: (s: string) => s.length })} 145 | ); 146 | 147 | log(transformedResult.nestedIdemPotent.str); // foo 148 | log(transformedResult.nestedIdemPotent.num); // 123 149 | // Doesn't compile, blah not found in transformedResult.nestedIdemPotent 150 | // log(transformedResult.nestedIdemPotent.blah); 151 | 152 | log(transformedResult.nestedChanged.str); // 3 153 | log(transformedResult.nestedChanged.num); // 123 154 | // Doesn't compile, blah not found in transformedResult.nestedChanged 155 | // log(transformedResult.nestedChanged.blah); 156 | }); 157 | 158 | it('Readme examples', () => { 159 | let transformedResult = transformObject( 160 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 161 | { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape }, 162 | { year: (obj) => obj.date.substr(0, 4) } 163 | ); 164 | 165 | // Doesn't compile : Argument of type "blah" doesn't exist on type 166 | // let blah = transformedResult.blah; 167 | 168 | // Doesn't compile : "type 'Date' is not assignable to type 'number'" 169 | // Proves that date2 has been converted to Date 170 | // let num: number = transformedResult.date2; 171 | 172 | log(transformedResult.date); // 1538604000000 173 | log(transformedResult.date2); // 2018-10-03T22:00:00.000Z (new Date(1538604000000)) 174 | log(transformedResult.aString); // Hello world 175 | log(transformedResult.idempotentValue); // foo 176 | log(transformedResult.year); // 2018 177 | 178 | let transformedResult2 = transformObject( 179 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 180 | { date: Date.parse, date2: (ts: number) => new Date(ts), aString: unescape } 181 | ); 182 | 183 | log(transformedResult2.date); // 1538604000000 184 | log(transformedResult2.date2); // 2018-10-03T22:00:00.000Z (new Date(1538604000000)) 185 | log(transformedResult2.aString); // Hello world 186 | log(transformedResult2.idempotentValue); // foo 187 | 188 | let transformedResult3 = transformObject( 189 | { date: "2018-10-04T00:00:00+0200", date2: 1538604000000, aString: "Hello%20World", idempotentValue: "foo" }, 190 | undefined, 191 | { year: (obj) => obj.date.substr(0, 4) } 192 | ); 193 | log(transformedResult3.date); // 2018-10-04T00:00:00+0200 194 | log(transformedResult3.date2); // 1538604000000 195 | log(transformedResult3.aString); // Hello%20world 196 | log(transformedResult3.idempotentValue); // foo 197 | log(transformedResult3.year); // 2018 198 | }); 199 | 200 | function log(message?: any, ...optionalParams: any[]): void { 201 | let logEnabled = false; // switch this in dev to enable console.log() 202 | if(logEnabled) { 203 | console.log(message, optionalParams); 204 | } 205 | } 206 | }); 207 | -------------------------------------------------------------------------------- /src/ts-object-transformer.ts: -------------------------------------------------------------------------------- 1 | 2 | // Thanks to Titian Cernicova-Dragomir https://stackoverflow.com/a/52641402/476345 3 | // and Matt McCutchen https://stackoverflow.com/a/52683426/476345 4 | export type FieldMap = { 5 | [ATTR in keyof SRC]?: (value: SRC[ATTR], obj?: SRC) => any 6 | }; 7 | export type ComputedMap = { 8 | [ATTR in keyof SRC]?: never 9 | } & { 10 | [ATTR: string]: (obj: SRC) => any 11 | }; 12 | export type MappedReturnType|undefined, CM extends ComputedMap|undefined> = 13 | (CM extends ComputedMap ? { [ATTR in keyof CM]: ReturnType } : unknown ) 14 | & { [ATTR in keyof SRC]: ATTR extends keyof FM 15 | ? FM[ATTR] extends (value: SRC[ATTR], obj?: SRC) => infer R ? R : SRC[ATTR] 16 | : SRC[ATTR] 17 | } 18 | 19 | export function transformObject< 20 | SRC extends object, FM extends FieldMap|undefined, CM extends ComputedMap|undefined 21 | >(src: SRC, fieldMap?: FM, computedMap?: CM): MappedReturnType { 22 | let result: any = {}; 23 | for(let key in src) { 24 | let value: any = src[key]; 25 | let transformedValue: any; 26 | if(fieldMap && (key in fieldMap)) { 27 | let transformer = fieldMap[key]; 28 | if(transformer) { 29 | transformedValue = transformer(value, src); 30 | } else { 31 | transformedValue = value; 32 | } 33 | } else { 34 | transformedValue = value; 35 | } 36 | result[key] = transformedValue; 37 | } 38 | 39 | if(computedMap) { 40 | for(let key in computedMap) { 41 | let transformer = <(obj: SRC) => any>computedMap[key]; 42 | result[key] = transformer(src); 43 | } 44 | } 45 | 46 | return result; 47 | } 48 | export default transformObject 49 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation. */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 12 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 13 | // "outFile": "./", /* Concatenate and emit output to single file. */ 14 | "outDir": "dist", /* Redirect output structure to the directory. */ 15 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 16 | // "composite": true, /* Enable project compilation */ 17 | "removeComments": true, /* Do not emit comments to output. */ 18 | // "noEmit": true, /* Do not emit outputs. */ 19 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 20 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 21 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 22 | 23 | /* Strict Type-Checking Options */ 24 | "strict": true, /* Enable all strict type-checking options. */ 25 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 26 | // "strictNullChecks": true, /* Enable strict null checks. */ 27 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 28 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 29 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 30 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 31 | 32 | /* Additional Checks */ 33 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 34 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 35 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 36 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 37 | 38 | /* Module Resolution Options */ 39 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 40 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 41 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 42 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 43 | // "typeRoots": [], /* List of folders to include type definitions from. */ 44 | // "types": [], /* Type declaration files to be included in compilation. */ 45 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 46 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 47 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 48 | 49 | /* Source Map Options */ 50 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 51 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 52 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 53 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 54 | 55 | /* Experimental Options */ 56 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 57 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 58 | }, 59 | "include": [ 60 | "src/**/*" 61 | ] 62 | } 63 | --------------------------------------------------------------------------------