You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+67-22
Original file line number
Diff line number
Diff line change
@@ -3,29 +3,38 @@
3
3
Typescript plugin that allows turning on strict mode in specific files or directories.
4
4
5
5
## Do I need this plugin?
6
-
`typescript-strict-plugin` was created mainly for existing projects that want to incorporate typescript strict mode, but project is so big that refactoring everything would take ages.
7
6
7
+
`typescript-strict-plugin` was created mainly for existing projects that want to incorporate
8
+
typescript strict mode, but project is so big that refactoring everything would take ages.
8
9
9
-
Our plugin allows adding strict mode to a TypeScript project without fixing all the errors at once. By adding `//@ts-strict-ignore` comment at the top of a file, its whole content will be removed from strict type checking. To ease migrating a project to use this plugin, you can use `update-strict-comments` script, which adds the ignore comment to all files that contain at least one strict error.
10
-
11
-
12
-
TypeScript plugins don't work at compile-time. They will show errors in your IDE, but they won't appear during compilation.
13
-
To check strict errors in marked files you can use `tsc-strict` script. This command line tool is created to check for files that should be checked with strict rules in compilation time.
14
-
It finds all relevant files and checks for strict typescript errors only for that files.
15
-
Therefore, we have strict errors inside our files and during build time.
10
+
Our plugin allows adding strict mode to a TypeScript project without fixing all the errors at once.
11
+
By adding `//@ts-strict-ignore` comment at the top of a file, its whole content will be removed from
12
+
strict type checking. To ease migrating a project to use this plugin, you can use
13
+
`update-strict-comments` script, which adds the ignore comment to all files that contain at least
14
+
one strict error.
16
15
16
+
TypeScript plugins don't work at compile-time. They will show errors in your IDE, but they won't
17
+
appear during compilation. To check strict errors in marked files you can use `tsc-strict` script.
18
+
This command line tool is created to check for files that should be checked with strict rules in
19
+
compilation time. It finds all relevant files and checks for strict typescript errors only for that
20
+
files. Therefore, we have strict errors inside our files and during build time.
17
21
18
22
## How to install
19
23
20
-
Use `npm`:
24
+
Use `npm`:
25
+
21
26
```bash
22
27
npm i --save-dev typescript-strict-plugin
23
28
```
24
-
or yarn
29
+
30
+
or yarn
31
+
25
32
```bash
26
33
yarn add -D typescript-strict-plugin
27
34
```
35
+
28
36
add plugin to your `tsconfig.json`:
37
+
29
38
```json
30
39
{
31
40
"compilerOptions": {
@@ -39,14 +48,22 @@ add plugin to your `tsconfig.json`:
39
48
}
40
49
}
41
50
```
51
+
42
52
and run the migration script
53
+
43
54
```
44
55
update-strict-comments
45
56
```
46
-
That's it! You should be able to see strict typechecking in files without the `@ts-strict-ignore` comment. To make these files strict too, just remove its' ignore comments.
57
+
58
+
That's it! You should be able to see strict typechecking in files without the `@ts-strict-ignore`
59
+
comment. To make these files strict too, just remove its' ignore comments.
47
60
48
61
## Configuration
49
-
Plugin takes one extra non-mandatory argument `paths` that is an array of relative or absolute paths of directories that should be included. To add strict mode to files from ignored paths you can insert `//@ts-strict` comment.
62
+
63
+
Plugin takes one extra non-mandatory argument `paths` that is an array of relative or absolute paths
64
+
of directories that should be included. To add strict mode to files from ignored paths you can
65
+
insert `//@ts-strict` comment.
66
+
50
67
```json
51
68
{
52
69
"compilerOptions": {
@@ -64,9 +81,11 @@ Plugin takes one extra non-mandatory argument `paths` that is an array of relati
64
81
}
65
82
}
66
83
```
84
+
67
85
All files contained in those paths will be strictly checked. Yay!
68
86
69
87
To add cli tool to your build time you can add a script to scripts list in package.json
88
+
70
89
```json
71
90
{
72
91
"scripts": {
@@ -76,55 +95,81 @@ To add cli tool to your build time you can add a script to scripts list in packa
76
95
}
77
96
```
78
97
79
-
Then you can simply run
98
+
Then you can simply run
99
+
80
100
```shell
81
101
yarn tsc-strict
82
102
```
83
103
84
104
All your strict files should be checked from command line.
85
105
86
106
You can also pass some `tsc` arguments to the `tsc-strict` to override default compiler options e.g.
107
+
87
108
```shell
88
109
yarn tsc-strict --strictNullChecks false
89
110
```
90
-
would not check for the strict null check in your files. The `tsc-strict` accepts all the arguments that regular `tsc` command
91
-
accepts.
111
+
112
+
would not check for the strict null check in your files. The `tsc-strict` accepts all the arguments
113
+
that regular `tsc` command accepts.
92
114
93
115
## Migrating to v2
94
-
Because of difficulties with migrating large projects to strict mode with original `//@ts-strict` comment, we've taken an another approach. Now in version 2.0+ typescript files are strict by default, and to ignore a file, you can use special `//@ts-strict-ignore` comment. It allows to have strict mode in newly created files without remembering about adding strict comment at the top of it. Version 2.0 comes with a new script `update-strict-comments`, which detects all files with at least one strict error and adds the ignore comment to ease the migration. To update from v1 to v2, you just need to run:
116
+
117
+
Because of difficulties with migrating large projects to strict mode with original `//@ts-strict`
118
+
comment, we've taken an another approach. Now in version 2.0+ typescript files are strict by
119
+
default, and to ignore a file, you can use special `//@ts-strict-ignore` comment. It allows to have
120
+
strict mode in newly created files without remembering about adding strict comment at the top of it.
121
+
Version 2.0 comes with a new script `update-strict-comments`, which detects all files with at least
122
+
one strict error and adds the ignore comment to ease the migration. To update from v1 to v2, you
123
+
just need to run:
124
+
95
125
```
96
126
update-strict-comments
97
127
```
128
+
98
129
## VSCode support
99
-
VSCode supports this plugin out of the box. However, sometimes it can use its own typescript version instead of the project one, resulting in not reading the local tsconfig. If you are using VSCode be sure to have `Use workspace version` option selected in `Typescript: Select Typescript Version...` command available in the [command pallete](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette).
100
130
131
+
VSCode supports this plugin out of the box. However, sometimes it can use its own typescript version
132
+
instead of the project one, resulting in not reading the local tsconfig. If you are using VSCode be
133
+
sure to have `Use workspace version` option selected in `Typescript: Select Typescript Version...`
0 commit comments