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
+20-77
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,16 @@
2
2
3
3
Typescript plugin that allows turning on strict mode in specific files or directories.
4
4
5
-
## Do i need this plugin?
6
-
This plugin was created for bigger repositories that want to incorporate typescript strict mode, but project is so big that refactoring everything would take ages. This plugin allows user to simply put `//@ts-strict` comment to a top of a file and turn a strict mode to that file. If needed, strict mode can be turned on to directories too.
7
-
Plugins in general doesn't work in compile time. They will show errors in your IDE but they won't appear during compilation.
8
-
To check strict errors in marked files you can use our script `tsc-strict`.
9
-
This command line tool is created to check for files that should be checked with strict rules in compilation time.
10
-
It finds all files with `//@ts-strict` comment and files specified in `paths` parameter and checks for strict typescript errors only for that files.
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
+
8
+
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 `tsc-strict --updateComment` 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.
11
15
Therefore, we have strict errors inside our files and during build time.
12
16
13
17
@@ -21,7 +25,7 @@ or yarn
21
25
```bash
22
26
yarn add -D typescript-strict-plugin
23
27
```
24
-
and add plugin to your `tsconfig.json`:
28
+
add plugin to your `tsconfig.json`:
25
29
```json
26
30
{
27
31
"compilerOptions": {
@@ -35,10 +39,14 @@ and add plugin to your `tsconfig.json`:
35
39
}
36
40
}
37
41
```
38
-
That's it! You should be able to use `@ts-strict` comment to strictly check your files.
42
+
and run the migration script
43
+
```
44
+
tsc-strict --updateComments
45
+
```
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.
39
47
40
48
## Configuration
41
-
Plugin takes one extra non-mandatory argument `paths` that is an array of relative or absolute paths of directories that should be included.
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.
would not check for the strict null check in your files. The `tsc-strict` accepts all the arguments that regular `tsc` command
83
91
accepts.
84
92
85
-
## Examples
86
-
Let's consider this type and a variable
87
-
```typescript
88
-
interfaceTestType {
89
-
bar:string;
90
-
}
91
-
92
-
const foo:TestType|undefined=undefined;
93
-
```
94
-
1. No `paths` argument
95
-
With `tsconfig.json` like this:
96
-
```json
97
-
{
98
-
"compilerOptions": {
99
-
...
100
-
"strict": false,
101
-
"plugins": [
102
-
{
103
-
"name": "typescript-strict-plugin"
104
-
}
105
-
]
106
-
}
107
-
}
108
-
```
109
-
Typescript will produce errors:
110
-
```typescript
111
-
//@ts-strict
112
-
...
113
-
const boo =foo.bar; // TS2532: Object is possibly 'undefined'.
114
-
```
115
-
Or not, depending on whether we used `ts-strict` or not:
116
-
```typescript
117
-
//no strict comment here
118
-
...
119
-
const boo =foo.bar; // no error here
120
-
```
121
-
122
-
2. With `paths` argument
123
-
With `tsconfig.json` like this:
124
-
```json
125
-
{
126
-
"compilerOptions": {
127
-
...
128
-
"strict": false,
129
-
"plugins": [
130
-
{
131
-
"name": "typescript-strict-plugin",
132
-
"path": "./src"
133
-
}
134
-
]
135
-
}
136
-
}
137
-
```
138
-
If file is in the directory typescript will produce errors even if `ts-strict` comment is not in the file :
139
-
```typescript
140
-
// ./src/index.ts
141
-
const boo =foo.bar; // TS2532: Object is possibly 'undefined'.
142
-
```
143
-
If file is not in the diretory there will be no error
144
-
```typescript
145
-
// ./lib/index.ts
146
-
const boo =foo.bar; // no error here
93
+
## 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. With version 2.0 script `tsc-strict` comes with a new flag, 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:
147
95
```
148
-
If file is not in the diretory but there is `ts-strict` file will be check with strict mode:
149
-
```typescript
150
-
// ./lib/index.ts
151
-
//@ts-strict
152
-
...
153
-
const boo =foo.bar; // TS2532: Object is possibly 'undefined'.
0 commit comments