{"name":"@putout/plugin-typescript","version":"12.3.0","keywords":["putout","putout-plugin","plugin","duplicates","union","mapped modifiers","typescript"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-typescript@12.3.0","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-typescript#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"228792a7fff1c0ca80f420b8d7968ff7d873266b","tarball":"http://registry-npm.ywwl.com/@putout/plugin-typescript/download/@putout/plugin-typescript-12.3.0.tgz","fileCount":31,"integrity":"sha512-PNy9JLmmHHQ8yAsTuSxjr6cylzhHoFurf3S1EfXi2/GY5qE+bX5PB5zfBce/H//wzp5lKqsGIx0LhG5HJQUfMQ==","signatures":[{"sig":"MEQCIFsM/NXgQ82vkH/StO0TbqrYXuy3esIuVy7n7PSsPIyBAiBapUJqza1axCCVlZK/rAgt8zlOoPEXDGJM6sb6MYl/rA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35545,"size":9232,"noattachment":false,"key":"/@putout/plugin-typescript/-/@putout/plugin-typescript-12.3.0.tgz"},"main":"lib/export.js","type":"module","engines":{"node":">=20"},"exports":{".":"./lib/export.js"},"gitHead":"b9e1f4c76b6f7251fe6c1b8e4e1c55aafae5b946","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"11.4.2","description":"🐊Putout plugin for transforming TypeScript code ","directories":{},"_nodeVersion":"24.4.1","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"^9.0.0","madrun":"^11.0.0","nodemon":"^3.0.1","@putout/test":"^13.0.0","eslint-plugin-n":"^17.0.0","@putout/eslint-flat":"^3.0.0","eslint-plugin-putout":"^28.0.0"},"peerDependencies":{"putout":">=40"},"_npmOperationalInternal":{"tmp":"tmp/plugin-typescript_12.3.0_1753532672012_0.4798499528474802","host":"s3://npm-registry-packages-npm-production"},"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- ✅ [convert-namespace-to-global](#convert-namespace-to-global);\n- ✅ [convert-empty-type-literal-to-record](#convert-empty-type-literal-to-record);\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/convert-namespace-to-global\": \"on\",\n        \"typescript/convert-empty-type-literal-to-record\": \"on\",\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 practice](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: unknown): 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## convert-namespace-to-global\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7b4036c8f4f7c02799e2fb5bcce865c8/f945baf6553ba7a9d0c95b7448bca4b82f7236e3).\n\n### ❌ Example of incorrect code\n\n```ts\ndeclare namespace global {\n    var al: any;\n}\n```\n\n### ✅ Example of correct code\n\n```ts\ndeclare global {\n    var al: any;\n}\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`typescript/convert-namespace-to-global`](https://github.com/coderaiser/putout/tree/master/packages/plugin-typescript#convert-namespace-to-global) | ✅\n⏣ **ESLint** | [`@typescript-eslint/no-namespace`](https://typescript-eslint.io/rules/no-namespace/) | ❌\n\n## convert-empty-type-literal-to-record\n\n> `{}` doesn't mean an empty object, but means any types other than `null` and `undefined`\n>\n> (c) [deno.com](https://docs.deno.com/lint/rules/ban-types/)\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6a6699b3f6ff1d707b732fd56323c329/a815410d21c9963bb1c8e974a1d0c93e6e53dd61).\n\n### ❌ Example of incorrect code\n\n```ts\ntype TestFunction<T extends Test = Test> = ((message: string, fn: (t: T) => void) => void) & {\n    extend<U extends CustomOperator = {}>(operators?: U): TestFunction<T & OperatorsToMethods<U>>;\n};\n```\n\n### ✅ Example of correct code\n\n```ts\ntype TestFunction<T extends Test = Test> = ((message: string, fn: (t: T) => void) => void) & {\n    extend<U extends CustomOperator = Record<PropertyKey, never>>(operators?: U): TestFunction<T & OperatorsToMethods<U>>;\n};\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`typescript/convert-namespace-to-global`](https://github.com/coderaiser/putout/tree/master/packages/plugin-typescript#convert-namespace-to-global) | ✅\n🦕 **Deno** | [`bun-types`](https://docs.deno.com/lint/rules/ban-types/) | ❌\n\n## remove-duplicates-from-union\n\n### ❌ Example of incorrect code\n\n```ts\ntype x =\n    | boolean[]\n    | A\n    | string\n    | A\n    | string[]\n    | boolean[];\n```\n\n### ✅ Example of correct code\n\n```ts\ntype x =\n    | 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    '/',\n    ['/hello.ts', '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":1753532672221,"_cnpm_publish_time":1753532672221,"dist-tags":{"latest":"13.2.1"}}