{"name":"@putout/plugin-typescript","version":"1.0.1","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"🐊Putout plugin for transforming TypeScript code ","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-typescript#readme","main":"lib/index.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git://github.com/coderaiser/putout.git"},"scripts":{"test":"madrun test","watch:test":"madrun watch:test","lint":"madrun lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report"},"dependencies":{},"keywords":["putout","putout-plugin","plugin","duplicates","union","mapped modifiers","typescript"],"devDependencies":{"@putout/test":"^4.0.0","c8":"^7.5.0","eslint":"^8.0.1","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^13.0.0","lerna":"^4.0.0","madrun":"^8.0.1","nodemon":"^2.0.1"},"peerDependencies":{"putout":">=24"},"license":"MIT","engines":{"node":">=14"},"publishConfig":{"access":"public"},"gitHead":"c6688563095e15a6a9e4b6f8b405725864a54cf6","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_id":"@putout/plugin-typescript@1.0.1","_nodeVersion":"16.13.1","_npmVersion":"8.3.0","dist":{"integrity":"sha512-cEteuyW2MUR5F1ScDyoBO4thxX7R6U5QjI/fqtLMyu4CkGZ8e4BzczKV/ptaEDHX+8PkqbRsEtOBZKiKN1Isig==","shasum":"e8eecbbe830af58a6f62839cd9ea25e36c6e72f6","tarball":"http://registry-npm.ywwl.com/@putout/plugin-typescript/download/@putout/plugin-typescript-1.0.1.tgz","fileCount":14,"unpackedSize":16540,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh4C3RCRA9TVsSAnZWagAAtLEP/1tCEWq/YrCfsq5mdd8m\neE7AWMYv+KUHtQDhag29nGo3YdfHxLT4UU752agk32O2QZUPWZhzzX9PPN9l\nukHsy97fBAP1m1XeDWAPYnNvGZod3X0OJiqCqzKxbGwzxFEEIsw7YJsXu+3t\nM5vEDFGQOaakHQ40BpLssU7a3T+A1uYdKA0q6sQtL54rQvoA9P4qgX40gqbA\ni9VqdhXtjE9U/S4q2FYXO13uKNmUuEt4X8Y/+bb4V1KWtfW6Qe29uOOpqNb4\nMhlbLu7mDBh6piw78YX5xJ8akXT1UWB1NuZN7MhtQNzks7Eokc8z4I2ZcZmG\njEBsc4L6XqBqLPLeu1+bdp/DkKUlOo/tv8On/DQdxTAvlZv1kyHHTk/ZCjEr\n77NSGs8nqtMlpo879bFFH1bHbqKbd0rKVykO/Oi7hu9x6QlaINxCMDQmQIlt\n9zr1LJBdBjTbiUhi9NnxjX3709bdNu4+f49FQTBjx8Lqn/BxCJ9wccry/gQr\nQhgydmjtvhngkUvUMN3zxeIL4c0LOMmSRZlnVJVDynIl1pQ9JcoOfPtjy2UQ\n6BfZ9Qy8T36xTi9amOntAhq09R4edSqWPnRMHkVnTktlkU2Zmty/SPgrFgI4\nGEyYXAmqhhKLMC/h2zqdpbHr9akUwl+QJtwDmOR6Hq9Ym8zlufdIvl6/UJfH\n5o+o\r\n=vDyS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDGwsYouooFmOrP1rikaZ/mqpxxVi9Y3Xvm7qe4OarMTwIhAIvcdKQB3GWn5O9VsJR3W+L6OT48zhpFkaBmWBklOw9+"}],"size":4675,"noattachment":false,"key":"/@putout/plugin-typescript/-/@putout/plugin-typescript-1.0.1.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/plugin-typescript_1.0.1_1642081745717_0.6990888145288214"},"_hasShrinkwrap":false,"readme":"# @putout/plugin-typescript [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-typescript.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-typescript \"npm\"\n\n> TypeScript is JavaScript with syntax for types.\n>\n> (c) [typescriptcriptlang.org](https://www.typescriptcriptlang.org)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform **TypeScript** code. Enabled by default for `ts` and `tsx` files.\n\n## Install\n\n```\nnpm i putout @putout/plugin-typescript -D\n```\n\n## Rules\n\n- ✅ [apply-as-type-assertion][#apply-as-type-assertion];\n- ✅ [apply-type-guards][#apply-type-guards];\n- ✅ [apply-utility-types][#apply-utility-types];\n- ✅ [convert-commonjs-to-esm][#convert-commonjs-to-esm];\n- ✅ [convert-esm-to-commonjs][#convert-esm-to-commonjs];\n- ✅ [convert-generic-to-shorthand][#convert-generic-to-shorthand];\n- ✅ [cts-file][#cts-file];\n- ✅ [filesystem.js][#filesystem.js];\n- ✅ [find-file][#find-file];\n- ✅ [mts-file][#mts-file];\n- ✅ [remove-duplicate-exports][#remove-duplicate-exports];\n- ✅ [remove-duplicate-interface-keys][#remove-duplicate-interface-keys];\n- ✅ [remove-duplicates-from-union][#remove-duplicates-from-union];\n- ✅ [remove-unused-types][#remove-unused-types];\n- ✅ [remove-getter-arguments][#remove-getter-arguments];\n- ✅ [remove-setter-return-type][#remove-setter-return-type];\n- ✅ [remove-useless-mapped-types][#remove-useless-mapped-types];\n- ✅ [remove-useless-mapping-modifiers][#remove-useless-mapping-modifiers];\n- ✅ [remove-useless-parens][#remove-useless-parens];\n- ✅ [remove-useless-promise][#remove-useless-promise];\n- ✅ [remove-useless-types][#remove-useless-types];\n- ✅ [remove-useless-types-from-constants][#remove-useless-types-from-constants];\n- ✅ [rename-file-cts-to-ts][#rename-file-cts-to-ts];\n- ✅ [rename-file-mts-to-ts][#rename-file-mts-to-ts];\n- ✅ [typescript.js][#typescript.js];\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"typescript/apply-as-type-assertion\": \"on\",\n        \"typescript/apply-utility-types\": \"on\",\n        \"typescript/apply-type-guards\": \"on\",\n        \"typescript/convert-generic-to-shorthand\": \"on\",\n        \"typescript/convert-commonjs-to-esm\": \"off\",\n        \"typescript/convert-esm-to-commonjs\": \"off\",\n        \"typescript/remove-duplicates-from-union\": \"on\",\n        \"typescript/remove-duplicates-interface-keys\": \"on\",\n        \"typescript/remove-duplicates-exports\": \"on\",\n        \"typescript/remove-useless-types-from-constants\": \"on\",\n        \"typescript/remove-unused-types\": \"on\",\n        \"typescript/remove-useless-types\": \"on\",\n        \"typescript/remove-useless-parens\": \"on\",\n        \"typescript/remove-useless-promise\": \"on\",\n        \"typescript/remove-getter-arguments\": \"on\",\n        \"typescript/remove-setter-return-type\": \"on\",\n        \"typescript/remove-useless-mapped-types\": \"on\",\n        \"typescript/cts-file\": \"off\",\n        \"typescript/mts-file\": \"off\",\n        \"typescript/rename-file-cts-to-ts\": \"off\",\n        \"typescript/rename-file-mts-to-ts\": \"off\",\n        \"typescript/find-file\": [\"off\", {\n            \"ignore\": []\n        }]\n    }\n}\n```\n\n## apply-as-type-assertion\n\nAccording to [best practise](https://stackoverflow.com/questions/36842158/arraytype-vs-type-in-typescript/36843084#36843084).\n\n### ❌ Example of incorrect code\n\n```ts\nconst boundaryElement = <HTMLElement>e.target;\n```\n\n### ✅ Example of correct code\n\n```ts\nconst boundaryElement1 = e.target as HTMLElement;\n```\n\n## apply-utility-types\n\n### ❌ Example of incorrect code\n\n```ts\ntype SuperType1 = {\n    [Key in keyof Type]?: Type[Key];\n};\n```\n\n### ✅ Example of correct code\n\n```ts\ntype SuperType1 = Partial<Type>;\n```\n\n## apply-type-guards\n\n> It just so happens that TypeScript has something called a `type guard`.\n> A `type guard` is some expression that performs a runtime check that guarantees the type in some scope.\n>\n> (c) [typescript.org](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards)\n\nCheck out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/5ac4459242197c4820b331f19d3681eb/4b66175c486ee8e865aee9645bf4e5fffc664e01).\n\n### ❌ Example of incorrect code\n\n```ts\nconst isNumber = (a) => typeof a === 'number';\n```\n\n### ✅ Example of correct code\n\n```ts\nconst isNumber = (a): a is number => typeof a === 'number';\n```\n\n## convert-generic-to-shorthand\n\n> There is no difference at all. `Type[]` is the shorthand syntax for an `array` of `Type`. `Array<Type>` is the generic syntax. They are completely equivalent.\n>\n> (c) https://stackoverflow.com/a/36843084/4536327\n\nConvert `generic` to `shorthand`.\n\n### ❌ Example of incorrect code\n\n```ts\ninterface A {\n    x: Array<X>;\n    y: Array<X | Y>;\n}\n```\n\n### ✅ Example of correct code\n\n```ts\ninterface A {\n    x: X[];\n    y: X[] | Y[];\n}\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`typescript/convert-generic-to-shorthand`](https://github.com/coderaiser/putout/tree/master/packages/plugin-typescript#convert-generic-to-shorthand) | ✅\n⏣ **ESLint** | [`@typescript-eslint/array-type`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/array-type.md#array-type) | ✅\n\n## convert-commonjs-to-esm\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/bb90e1d40107f2e76f528053ef576bd2/d10cd8374c7a792d3ff1225ca5ac639c71da7207).\n\n### ❌ Example of incorrect code\n\n```ts\nimport foo = require('foo');\nexport = 5;\n```\n\n### ✅ Example of correct code\n\n```ts\nimport foo from 'foo';\n\nexport default 5;\n```\n\n## convert-commonjs-to-esm\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7f77665246b03d9eddc8ee35713c415b/f874630569fa856e62c8a1564c31115ac82f182e).\n\n### ❌ Example of incorrect code\n\n```ts\nimport foo from 'foo';\n\nexport default 5;\n```\n\n### ✅ Example of correct code\n\n```ts\nimport foo = require('foo');\nexport = 5;\n```\n\n## remove-duplicates-from-union\n\n### ❌ Example of incorrect code\n\n```ts\ntype x = boolean[]\n    | A\n    | string\n    | A\n    | string[]\n    | boolean[];\n```\n\n### ✅ Example of correct code\n\n```ts\ntype x = boolean[]\n    | A\n    | string\n    | string[];\n```\n\n## remove-duplicates-exports\n\nIn **JavaScript** duplicate exports leads to [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError), anyways **TypeScript** parses such code and reports [`Duplicates Identifier`](https://github.com/Microsoft/TypeScript/blob/v1.8.5/src/compiler/diagnosticMessages.json#L826-L829) diagnostic.\n\nIt gives us ability to automate fixing of such code 😏. Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e8d02b3d1c91b4b3b6b9636e22dd03ed/8be7b4c8d0f6c28440f36d03341a1153c18549a7).\n\n### ❌ Example of incorrect code\n\n```ts\nexport {\n    a,\n    hello,\n    a,\n    world,\n};\n```\n\n#### ✅ Example of correct code\n\n```ts\nexport {\n    hello,\n    a,\n    world,\n};\n```\n\n*☝️ The rule fits good with [`putout/add-newlines-between-specifiers`](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/add-newlines-between-specifiers#readme) of [**eslint-plugin-putout**](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/#readme).*\n\n### remove-getter-arguments\n\n> The `get` syntax binds an object property to a function that will be called when that property is looked up\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get)\n\n#### ❌ Example of incorrect code\n\n```ts\nexport interface IParamsConstructor {\n    get [fromArray](name: string): IParams;\n}\n```\n\n#### ✅ Example of correct code\n\n```ts\nexport interface IParamsConstructor {\n    get [fromArray](): IParams;\n}\n```\n\n### remove-setter-return-type\n\n> The `set` syntax binds an object property to a function to be called when there is an attempt to set that property.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set)\n\n#### ❌ Example of incorrect code\n\n```ts\nexport interface IParamsConstructor {\n    set fromArray(values: ParamsArray): string;\n}\n```\n\n#### ✅ Example of correct code\n\n```ts\nexport interface IParamsConstructor {\n    set fromArray(values: ParamsArray);\n}\n```\n\n### remove-useless-types-from-constants\n\n#### ❌ Example of incorrect code\n\n```ts\nconst x: any = 5;\n```\n\n#### ✅ Example of correct code\n\n```ts\nconst x = 5;\n```\n\n## remove-unused-types\n\n### ❌ Example of incorrect code\n\n```ts\ntype n = number;\ntype s = string;\n\nconst x: n = 5;\n```\n\n### ✅ Example of correct code\n\n```ts\ntype n = number;\n\nconst x: n = 5;\n```\n\n## remove-useless-types\n\n### ❌ Example of incorrect code\n\n```ts\ntype oldType = {\n    a: number;\n    b: string;\n};\ntype newType = oldType;\n\nconst x: newType = {\n    a: 5,\n    b: 'hello',\n};\n```\n\n### ✅ Example of correct code\n\n```ts\ntype oldType = {\n    a: number;\n    b: string;\n};\n\nconst x: oldType = {\n    a: 5,\n    b: 'hello',\n};\n```\n\n## remove-useless-parens\n\nCheck it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6c8717114f7285639a5f24b5a6fdb9dc/583e438a61aae156c79b66dbf418e1e5f251bf87).\n\n### ❌ Example of incorrect code\n\n```ts\nconst m: X[] = [];\nconst z: (X | Y) = 5;\nconst f: X = 5;\n```\n\n### ✅ Example of correct code\n\n```ts\nconst x: X[] | Y[] = [];\nconst m: X[] = [];\nconst z: X | Y = 5;\nconst f: X = 5;\n```\n\n## remove-useless-promise\n\nCheck it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/5fd13c0510571b45884dfddbc8b83bb4/5ca97c4021b197822ef73418796513fe6d891239).\n\n### ❌ Example of incorrect code\n\n```ts\nfunction doStuff(): Promise<string> {\n    return 'hello';\n}\n```\n\n### ✅ Example of correct code\n\n```ts\nfunction doStuff(): string {\n    return 'hello';\n}\n```\n\n## remove-useless-mapped-types\n\nRemove useless [mapped types](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html).\n\n### ❌ Example of incorrect code\n\n```ts\ntype SuperType = {\n    [Key in keyof Type]: Type[Key];\n};\n```\n\n### ✅ Example of correct code\n\n```ts\ntype SuperType = Type;\n```\n\n## remove-useless-mapping-modifiers\n\nRemove useless [mapping modifiers](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#mapping-modifiers).\n\n### ❌ Example of incorrect code\n\n```ts\ntype SuperType = {\n    [Key in keyof Type]+?: Type[Key];\n};\n```\n\n### ✅ Example of correct code\n\n```ts\ntype SuperType = {\n    [Key in keyof Type]?: Type[Key];\n};\n```\n\n## remove-duplicate-interface-keys\n\n### ❌ Example of incorrect code\n\n```ts\ninterface Hello {\n    'hello': any;\n    'hello': string;\n}\n```\n\n### ✅ Example of correct code\n\n```ts\ninterface Hello {\n    'hello': string;\n}\n```\n\n## cts-file\n\nRun [convert-esm-to-commonjs](#convert-esm-to-commonjs) for all `*.cts` files with help of [redlint](https://github.com/putoutjs/redlint).\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/0beac7eb211cf57be282f6744fc54410/f4217bf6e392e33871152318adce4e3ef6db2dd6).\n\n## mts-file\n\nRun [convert-esm-to-commonjs](#convert-commonjs-to-esm) for all `*.mts` files with help of [redlint](https://github.com/putoutjs/redlint).\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/0beac7eb211cf57be282f6744fc54410/f4217bf6e392e33871152318adce4e3ef6db2dd6).\n\n## find-file\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1026c5e9562248e7f07f9e2c7b698650/8c701bba5ba52f4cac258ecf5dcb5bee1f197236).\n\n### ❌ Example of incorrect code\n\n```ts\n__putout_processor_filesystem(['/', [\n    '/hello.ts',\n    'const a: number = 5;',\n]]);\n```\n\n### ✅ Example of correct code\n\n```ts\n__putout_processor_filesystem(['/', [\n    '/hello.ts',\n    'const a = 5;',\n]]);\n```\n\n## rename-file-cts-to-ts\n\nRename `*.cts` files when `type === \"commonjs\"`:\n\n```diff\n /\n |-- package.json\n `-- lib/\n-     `-- hello.cts\n+     `-- hello.ts\n```\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/8d8f3cd6662b70abbd5e4a2e4835077f/e43319fd63291ec3a5028b30a83f3c91fe90325e).\n\n## rename-file-mts-to-ts\n\nRename `*.mts` files when `type === \"module\"`:\n\n```diff\n /\n |-- package.json\n `-- lib/\n-     `-- hello.mts\n+     `-- hello.ts\n```\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/8d8f3cd6662b70abbd5e4a2e4835077f/e43319fd63291ec3a5028b30a83f3c91fe90325e).\n\n## License\n\nMIT\n","publish_time":1642081745927,"_cnpm_publish_time":1642081745927,"dist-tags":{"latest":"13.2.1"}}