|
1 | 1 | # Extras |
2 | 2 |
|
3 | 3 | ### tsconfig.json |
4 | | -> - Recommended setup for best benefits from type-checking, with support for JSX and ES2016 features |
5 | | -> - Add [`tslib`](https://www.npmjs.com/package/tslib) to minimize bundle size: `npm i tslib` - this will externalize helper functions generated by transpiler and otherwise inlined in your modules |
6 | | -> - Include absolute imports config working with Webpack |
| 4 | +- Recommended setup for best benefits from type-checking, with support for JSX and ES2016 features |
| 5 | +- Add [`tslib`](https://www.npmjs.com/package/tslib) to minimize bundle size: `npm i tslib` - this will externalize helper functions generated by transpiler and otherwise inlined in your modules |
| 6 | +- Include absolute imports config working with Webpack |
7 | 7 |
|
8 | 8 | ```js |
9 | 9 | { |
|
55 | 55 |
|
56 | 56 | [⇧ back to top](#table-of-contents) |
57 | 57 |
|
58 | | -### tslint.json |
59 | | -> - Recommended setup is to extend build-in preset `tslint:recommended` (for all rules use `tslint:all`) |
60 | | -> - Add tslint react rules: `npm i -D tslint-react` https://github.com/palantir/tslint-react |
61 | | -> - Amended some extended defaults for more flexibility |
62 | | -
|
63 | | -```json |
64 | | -{ |
65 | | - "extends": ["tslint:recommended", "tslint-react"], |
66 | | - "rules": { |
67 | | - "arrow-parens": false, |
68 | | - "arrow-return-shorthand": [false], |
69 | | - "comment-format": [true, "check-space"], |
70 | | - "import-blacklist": [true, "rxjs"], |
71 | | - "interface-over-type-literal": false, |
72 | | - "interface-name": false, |
73 | | - "max-line-length": [true, 120], |
74 | | - "member-access": false, |
75 | | - "member-ordering": [true, { "order": "fields-first" }], |
76 | | - "newline-before-return": false, |
77 | | - "no-any": false, |
78 | | - "no-empty-interface": false, |
79 | | - "no-import-side-effect": [true], |
80 | | - "no-inferrable-types": [true, "ignore-params", "ignore-properties"], |
81 | | - "no-invalid-this": [true, "check-function-in-method"], |
82 | | - "no-null-keyword": false, |
83 | | - "no-require-imports": false, |
84 | | - "no-submodule-imports": [true, "@src", "rxjs"], |
85 | | - "no-this-assignment": [true, { "allow-destructuring": true }], |
86 | | - "no-trailing-whitespace": true, |
87 | | - "no-unused-variable": [true, "react"], |
88 | | - "object-literal-sort-keys": false, |
89 | | - "object-literal-shorthand": false, |
90 | | - "one-variable-per-declaration": [false], |
91 | | - "only-arrow-functions": [true, "allow-declarations"], |
92 | | - "ordered-imports": [false], |
93 | | - "prefer-method-signature": false, |
94 | | - "prefer-template": [true, "allow-single-concat"], |
95 | | - "quotemark": [true, "single", "jsx-double"], |
96 | | - "semicolon": [true, "always"], |
97 | | - "trailing-comma": [true, { |
98 | | - "singleline": "never", |
99 | | - "multiline": { |
100 | | - "objects": "always", |
101 | | - "arrays": "always", |
102 | | - "functions": "never", |
103 | | - "typeLiterals": "ignore" |
104 | | - }, |
105 | | - "esSpecCompliant": true |
106 | | - }], |
107 | | - "triple-equals": [true, "allow-null-check"], |
108 | | - "type-literal-delimiter": true, |
109 | | - "typedef": [true,"parameter", "property-declaration"], |
110 | | - "variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case", "allow-leading-underscore"], |
111 | | - // tslint-react |
112 | | - "jsx-no-lambda": false |
113 | | - } |
114 | | -} |
115 | | -``` |
116 | | - |
117 | | -[⇧ back to top](#table-of-contents) |
118 | | - |
119 | | -### jest.config.json |
120 | | -> - Recommended setup for Jest with TypeScript |
121 | | -> - Install with `npm i -D jest-cli ts-jest @types/jest` |
122 | | -
|
123 | | -```json |
124 | | -{ |
125 | | - "verbose": true, |
126 | | - "transform": { |
127 | | - ".(ts|tsx)": "./node_modules/ts-jest/preprocessor.js" |
128 | | - }, |
129 | | - "testRegex": "(/spec/.*|\\.(test|spec))\\.(ts|tsx|js)$", |
130 | | - "moduleFileExtensions": [ |
131 | | - "ts", |
132 | | - "tsx", |
133 | | - "js" |
134 | | - ], |
135 | | - "globals": { |
136 | | - "window": {}, |
137 | | - "ts-jest": { |
138 | | - "tsConfigFile": "./tsconfig.json" |
139 | | - } |
140 | | - }, |
141 | | - "setupFiles": [ |
142 | | - "./jest.stubs.js", |
143 | | - "./src/rxjs-imports.tsx" |
144 | | - ] |
145 | | -} |
146 | | -``` |
147 | | - |
148 | | -[⇧ back to top](#table-of-contents) |
149 | | - |
150 | 58 | ### Default and Named Module Exports |
151 | 59 | > Most flexible solution is to use module folder pattern, because you can leverage both named and default import when you see fit. |
152 | 60 | Using this solution you'll achieve better encapsulation for internal structure/naming refactoring without breaking your consumer code: |
@@ -212,16 +120,3 @@ declare module 'rxjs/Subject' { |
212 | 120 | > More advanced scenarios for working with vendor module declarations can be found here [Official TypeScript Docs](https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Modules.md#working-with-other-javascript-libraries) |
213 | 121 |
|
214 | 122 | [⇧ back to top](#table-of-contents) |
215 | | -
|
216 | | -### Npm Scripts |
217 | | -> Common TS-related npm scripts shared across projects |
218 | | -``` |
219 | | -"check": "npm run lint & npm run tsc", |
220 | | -"lint": "tslint --project './tsconfig.json'", |
221 | | -"tsc": "tsc -p . --noEmit", |
222 | | -"tsc:watch": "tsc -p . --noEmit -w", |
223 | | -"test": "jest --config jest.config.json", |
224 | | -"test:watch": "jest --config jest.config.json --watch", |
225 | | -``` |
226 | | -
|
227 | | -[⇧ back to top](#table-of-contents) |
0 commit comments