{"name":"@putout/plugin-typescript","version":"8.3.0","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","exports":{".":"./lib/index.js"},"release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git+https://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":"^11.0.0","c8":"^10.0.0","eslint":"^9.0.0","eslint-plugin-n":"^17.0.0","eslint-plugin-putout":"^23.0.0","lerna":"^6.0.1","madrun":"^10.0.0","nodemon":"^3.0.1"},"peerDependencies":{"putout":">=36"},"license":"MIT","engines":{"node":">=18"},"publishConfig":{"access":"public"},"_id":"@putout/plugin-typescript@8.3.0","gitHead":"177b5946b7b15c99af6c9facd11a216773371d02","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_nodeVersion":"22.8.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-qkS7zW44ENC5+qweTLJuYTnTBayWO3lHjcMJqTT6m+z8phwrM9TnPZZ9jvNDFkQdQSV50HFOEgVbILjyRBftiQ==","shasum":"387f20004c34eaad59648c610f2edc02d41d9509","tarball":"http://registry-npm.ywwl.com/@putout/plugin-typescript/download/@putout/plugin-typescript-8.3.0.tgz","fileCount":30,"unpackedSize":34246,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFMVK69KXOGEaiP/5ANh6+Os6Fp1z2avLQPYl46f02kqAiA038iZbywQt5YqSbasnfttysqNQkkXqKDPhvgPa4NqzA=="}],"size":8955,"noattachment":false,"key":"/@putout/plugin-typescript/-/@putout/plugin-typescript-8.3.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/plugin-typescript_8.3.0_1730021053316_0.6488614216062418"},"_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- ✅ [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-non-null-expressions](#remove-useless-non-null-expressions);\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\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/remove-useless-non-null-expressions\": \"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-esm-to-commonjs\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-duplicate-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-non-null-expressions\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7a7b37619981d2b2667a709aed96aa26/4bf8d219803979ccb8777e732aa095ce4425dff5).\n\n### ❌ Example of incorrect code\n\n```ts\nconst bar = foo!!.str;\nconst baz = bar!?.n;\n```\n\n### ✅ Example of correct code\n\n```ts\nconst bar = foo!.str;\nconst baz = bar?.n;\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":1730021053538,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1730021053538,"dist-tags":{"latest":"13.2.1"}}