0.2.5 • Published 1 year ago

ts-remove-any v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

ts-remove-any

ts-remove-any will replace automatically some implicit (and explicit) anys with a compatible type.

Motivation

If you have an existing TypeScript project, you may want to turn noImplicitAny on, as it really helps to find errors at build time instead of waiting for the program to crash.

But if your project was not started with this option activated, you may be discouraged by the number of errors appearing when turning it on.

If that's the case, ts-remove-any is here for you: it will rewrite part of your code, replacing implicit anys by a (probably) compatible type.

This project is conservative in the sense that it tries to minimize the number of fixes you have to do afterward. It means that it won't fix all your implicit anys, only those with a good chance to not be wrong. But even like this, there may still be some errors; it's to be expected, as any is an escape hatch usually used to prevent TypeScript to check properly the code.

This project cannot completely eliminate the need for manual code fixes, but it can assist in this task.

Usage

Run the following command at the root folder of your project:

npx ts-remove-any

Don't forget to run your formatter (eg. prettier) and typechecker (eg. tsc) afterward, ts-remove-any may reformat your code, and leave some type errors.

The execution can be quite slow; if you wan to monitor the advancement of the execution, add the verbose flag.

npx ts-remove-any -v

More options are available, and can be found from the cli help.

OptionEffect
-vincrease the verbosity, ie. the amount of logs displayed. Can be double to see even more logs: -v -v
-pthe path of tsconfig.json file to use
-fa pattern against which the file name and path will be matched. Useful if you want to run ts-remove-any only on one file, or group of files
-rdon't revert the code in case of errors. ts-remove-any may generate invalid types, this option will ensure that we keep those types. They may be used as a basis for a manual fix
-ddry-run, don't apply any change, but display a log of the changes that would be made
-ealso replace the explicit anys
--helpdisplay a contextual help

You may have to increase the memory available to node, as this project uses a lot of memory. It can done with the following command:

NODE_OPTIONS=--max-old-space-size=8192 npx ts-remove-any

It could be useful to run the script multiple times, until the number of changes done are 0: each time ts-remove-any removes some anys, new types are available to analysis and remove other anys.

This is not done automatically as you may want to check intermediate results between run, to ensure types generated are valid.

Release procedure

./script/release.sh
0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.1.61

1 year ago

0.1.60

1 year ago

0.1.59

1 year ago

0.1.58

1 year ago

0.1.57

1 year ago

0.1.56

1 year ago

0.1.55

1 year ago

0.1.54

1 year ago

0.1.53

1 year ago

0.1.52

1 year ago

0.1.51

1 year ago

0.1.50

1 year ago

0.1.49

1 year ago

0.1.48

1 year ago

0.1.47

1 year ago

0.1.46

1 year ago

0.1.45

1 year ago

0.1.44

1 year ago

0.1.43

1 year ago

0.1.42

1 year ago

0.1.41

1 year ago

0.1.40

1 year ago

0.1.39

1 year ago

0.1.38

1 year ago

0.1.37

1 year ago

0.1.36

1 year ago

0.1.35

1 year ago

0.1.34

1 year ago

0.1.33

1 year ago

0.1.32

1 year ago

0.1.31

1 year ago

0.1.30

1 year ago

0.1.29

1 year ago

0.1.28

1 year ago

0.1.27

1 year ago

0.1.26

1 year ago

0.1.25

1 year ago

0.1.24

1 year ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago