allegro / typescript-strict-plugin Goto Github PK
View Code? Open in Web Editor NEWTypescript plugin that allows turning on strict mode in specific files or directories.
License: MIT License
Typescript plugin that allows turning on strict mode in specific files or directories.
License: MIT License
I have an existing Typescript code base which does not follow Typescript strict mode but I want to have all new added files to be automatically enforced to be in strict mode.
At the moment it's not possible to accomplish without either fixing all existing code base and enable strict: true
in tsconfig.json
or relying on good intentions of including @//ts-strict
in every new Typescript file
Having //@ts-strict-ignore
option allows to accomplish this in a smarter way.
First, I can have a configuration like this:
{
"compilerOptions": {
...
"strict": false
"plugins": [
{
"name": "typescript-strict-plugin".
"paths": ["./src"]
}
]
}
}
Then I can add //@ts-strict-ignore
to all existing Typescript file in my codebase and can incrementally fix these files and remove the comment.
And now, when new file is added, it will be automatically enforced to follow strict mode unless //@ts-strict-ignore
is explicitly added.
I'm curious what do you think about the idea or have alternative ways to implement this?
Greetings! π
We're currently in the process of upgrading our Angular project, which uses Betterer in combination with your exceptional plugin which allows us to gradually enforce stricter codebase parameters over time.
However, we've encountered a problem during our upgrade from Angular v15
to v17
and Typescript to its latest version, [email protected]
. The issue arises with IDEs (WebStorm, IntelliJ IDEA Ultimate, VS Code) failing to display strictness issues in files which are strict.
After downgrading Typescript version by version in an attempt to pinpoint the problem, it seems the issue dissipates with version [email protected]
.
To reproduce this issue, I've created a minimal Angular application located here. This application uses:
I initiated a new project using the Angular CLI, installed your current plugin, and configured it via tsconfig.json
(disabling strictness and adding the plugin). In app.component
, I inserted a strictness error. This error is not reported with [email protected]
, yet is correctly identified with [email protected]
. The snippet of code in question is as follows:
/**
* with typescript version higher than 5.3.3 this reports no strictness error, but it should.
* if we downgrade typescript to 5.3.3, a strictness error will be shown here.
*/
strictnessError(): string {
return undefined;
}
I noticed an issue with [email protected]
was reported and fixed last week as per this issue, but it seems there might still be a lingering problem.
Thanks in advance for your assistance!
Mariusz
The plugin isn't working with angular and TS. Not strict lines don't mark as errors.
"typescript-strict-plugin":1.0.1
"typescript": "4.0.2"
"@angular-builders/custom-webpack": "10.0.1",
"@angular-devkit/build-angular": "~0.1001.0",
"@angular-devkit/build-ng-packagr": "~0.1001.0",
"@angular/cli": "11.0.0",
"@angular/compiler-cli": "11.0.0",
"@angular/language-service": "11.0.0",
Great plugin for partial strict mode refactoring. But I want to exclude files like *.spec.ts
(unit test).
tsconfig.json (my current config)
{
"strict": false,
"plugins": [
{
"name": "typescript-strict-plugin",
"paths": ["./src"]
}
]
}
Split paths
to include
and exclude
similar like the tsconfig one.
Hi,
I'm using your plugin well to increase strict code in a non-strict project.
But I'm facing one problem
// @ts-strict
added using typescript-strict-plugin -> type catching// @ts-strict
-> library is not strict.Of course, this is not the role of typescript-strict-plugin, so it's normal,
But we can't just add // @ts-strict
to a library in node_modules, can we?
So I thought about adding a config.forceInclude
similar to config.exclude
.
If it's included in config.forceInclude
, it will be strict even if it doesn't have // @ts-strict
.
Anyway, thanks for the library, I'm enjoying using it!
Hi there, I'm using neovim with the typescript-language-server
language server. How can I see my strict violations using this language server?
I use mason to manage my LSP configs, so the version installed gets installed by mason as:
/Users/beau/.local/share/nvim/mason/packages/typescript-language-server/node_modules/typescript/lib/tsserver.js
Anyone had luck getting this working in vim?
Has this plugin stopped working with Visual Studio Code (tested 1.83.1 and 1.85.0) for anyone else? I'm observing some weird behavior when switching between regular and ts-strict-ignore files where sometimes ignored files report strictness diagnostics and sometimes normal files do no report strictness diagnostics. There is also a tendency for vscode to hang indefinitely with "Loading IntelliSense status" which results in no new diagnostics being produced (seems the language service hangs).
At first I thought it was simply that the first file which requests diagnostics set the strictness of the rest of the session but it seems this is not the case.
Interestingly I do not observe these issues when using my fork where I'm experimenting with keeping a separate TS program in-memory instead of mutating the compiler options of the language service. The fork can be found here: https://github.com/hnra/typescript-strict-plugin. I have tested this fork out on a project with 100k+ LOC and it seems to work well and fixes these issues. I can open a PR if we want to discuss upstreaming the changes.
typescript-strict-plugin version: 2.2.1
TypeScript version: 5.3.3 and 5.2.2
Visual Studio Code: 1.83.1 and 1.85.0
We need to run our typescript transpilation process with NODE_OPTIONS='--max-old-space-size=8192'
. Subsequently running the typecheck has the following issue:
max@host master ~/code$ npx tsc-strict
Project does not contain any strict files.
is reported incorrectly whereas
max@host master ~/code$ NODE_OPTIONS='--max-old-space-size=8192' npx tsc-strict
π― Found 1062 strict files
π All files passed
yields the correct result. I think typecheck should not succeed in the first place for out-of-memory errors and populate this error instead. Probably is related to tsc
being called with the noEmit
option. The terminal error response ($?
evaluates to 1) is actually correct, but no obvious output is available.
Found by a colleague actually, not my credit.
Currently we use "strict": true
but have "strictNullChecks": false
. When we run yarn tsc-strict
we get π All files passed
.
{
"compilerOptions": {
...
"strict": true,
"strictNullChecks": false,
"plugins": [
{
"name": "typescript-strict-plugin"
}
]
}
}
I am not sure how the plugin should work but I thought it would ignore the strictNullChecks
and make it true
.
I would like to keep the tsconfig.json
as is and not remove "strictNullChecks": false
so it can work with our current workflow. Can you allow tsc-strict
to take the --project
and -p
command line options so we can point to another file (tsc-strict -p tsconfig-strict.json
)?
Reproduction Steps:
Expected:
The window for automatic import update should show
Actual:
The window to ask for automatic imports update doesn't come up
If you do a full window reload, everything works as expected
We've been looking at adopting this plugin in our very large project and noticed that switching between files which are marked as strict and files which are not can be very slow (in the order of 10s of seconds). That seems to be because the plugin needs to switch strict
on and off in the language server based on the presence of the @ts-strict-ignore
comments. This slowness makes the plugin very disruptive to use on a day-to-day basis, at least until most of our codebase has been made strict and we don't need to switch strict
on/off so often.
Maybe this occurred to you as well but the following came to mind: could we run two tsserver instances in parallel, one with strict
enabled and the other one with it disabled? If possible, it should avoid the cost of switching a single tsserver between strict and non-strict mode in very large codebases (those which typically are harder to make strict).
I suppose to make this happen one would have to create a custom tsserver which would start two child tsserver processes and proxy any requests from the IDE to the right child process based on the presence (or lack) of the @ts-strict-ignore
comment.
What do you think? Have you maybe tried going down this route?
Is it possible to add an option to pass a list of files?
My use case is only check changed files. The easiest way to achieve this is passing the files as an argument to tsc-strict
Title pretty much sums it up. Was just wondering why an error would be returned in the event that no files match the strict criteria. This may be desired behavior; for instance, I intentionally set the "paths" array such that no files would be checked. In this case I'd expect the build script to continue successfully when using "npm run build tsc-strict && other-script"; instead it fails.
Hi,
Because tsc-strict
ends up to run tsc --strict --noEmit ...process.argv.slice(2)
:
tsc-strict -b apps/fr-app/tsconfig.json
π― Found 10794 strict files
β Έ Compiling with strict mode...π₯ Typescript did not compile due to some errors. Errors: [
"error TS6369: Option '--build' must be the first command line argument."
emitDeclarationOnly
option:Ξ» βΊ tsc-strict
π― Found 10794 strict files
β ΄ Compiling with strict mode...π₯ Typescript did not compile due to some errors. Errors: [
"error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'."
]
Maybe passing the process.argv before strict could be enough for the build option, but I don't know if the noEmit option is really required.
Also, for the record, I've a project with 13106 ts files, and tsc-strict is very longer than tsc (mainly because of the Looking for strict files step). Maybe a cache could be considered?
I'm ready to do the PR when we agree on what to do.
Thanks for your package!
This might help for scenarios where //@ts-strict is available, but not everyone on the dev team knows about it or maybe has forgotten to use it, and also just to avoid the manual effort of trying to figure out which files are already strict compatible.
Along this same train of thought... another idea could be a pre-commit hook that checks to make sure new TS files have //@ts-strict and checks to see if existing ones can have //@ts-strict added to them.
In the latest version of VSCode, the plugin doesn't seem to show any diagnostics in the IDE. However, when running the script tsc-strict
it works fine.
Here's the tsconfig.json on windows.
"plugins": [ { "name": "typescript-strict-plugin", "paths": ["./src/v2"] } ]
Working fine with //@ts-strict but doesn't work when I set
{ ... "plugins": [ { "name": "typescript-strict-plugin", "paths": [ "./src/v2" ] } ] }
I'd like to run this as a pre-commit hook and only check staged files so I can
I think I could achieve 1) myself by creating a temporary tsconfig.json file with the staged files listed as files
and feed that to the CLI, but it would be much better if the command could directly handle a list of files.
Is that technically possible?
For 2), I would also appreciate exposing a new cli command which takes a list of files and throws an error if any of them are ignored
As in title.
Reproduction
//@ts-strict
to a file without any strict errorsupdate-strict-comments
TypeScript Version: 4.9.3
Steps to reproduce crash
Global TS Server Plugins
typescript-tslint-plugin
TS Server Log
[Info - 19:16:20.649] Starting TS Server
[Info - 19:16:20.649] Using tsserver from: d:\Work\my_project\node_modules\typescript\lib\tsserver.js
[Info - 19:16:20.650] <syntax> Forking...
[Info - 19:16:20.659] <syntax> Starting...
[Info - 19:16:20.660] <semantic> Forking...
[Info - 19:16:20.670] <semantic> Starting...
[Info - 19:57:33.799] Killing TS Server
[Error - 19:57:33.826] TSServer exited. Code: null. Signal: SIGTERM
[Info - 19:57:33.827] Starting TS Server
[Info - 19:57:33.828] Using tsserver from: d:\Work\my_project\node_modules\typescript\lib\tsserver.js
[Info - 19:57:33.830] <syntax> Forking...
[Info - 19:57:33.839] <syntax> Starting...
[Info - 19:57:33.841] <semantic> Forking...
[Info - 19:57:33.850] <semantic> Starting...
TS Server Error Stack
Server: semantic
TypeError: Cannot read properties of undefined (reading 'configFileSpecs')
at ConfiguredProject.updateErrorOnNoInputFiles (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:175434:120)
at ProjectService.reloadFileNamesOfConfiguredProject (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:177258:25)
at ConfiguredProject.updateGraph (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:175280:54)
at updateProjectIfDirty (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:175781:45)
at ProjectService.assignProjectToOpenedScriptInfo (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:178113:29)
at d:\Work\my_project\node_modules\typescript\lib\tsserver.js:178448:97
at Object.flatMap (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:524:25)
at ProjectService.applyChangesInOpenFiles (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:178448:41)
at Session.handlers.ts.Map.ts.getEntries._a.<computed> (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:179820:46)
at d:\Work\my_project\node_modules\typescript\lib\tsserver.js:182013:96
at Session.executeWithRequestId (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:182004:28)
at Session.executeCommand (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:182013:41)
at Session.onMessage (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:182041:35)
at process.<anonymous> (d:\Work\my_project\node_modules\typescript\lib\tsserver.js:186197:31)
at process.emit (node:events:526:28)
at emit (node:internal/child_process:938:14)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
VS Code version: Code 1.73.1 (6261075646f055b99068d3688932416f2346dd3b, 2022-11-09T04:27:29.066Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: No
Item | Value |
---|---|
CPUs | Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 x 2592) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
Load (avg) | undefined |
Memory (System) | 31.83GB (19.79GB free) |
Process Argv | --folder-uri file:///d%3A/Work/my_project --crash-reporter-id a2588ac5-1805-41b7-8761-35aa1d6a80e2 |
Screen Reader | no |
VM | 0% |
Extension | Author (truncated) | Version |
---|---|---|
vscode-eslint | dba | 2.2.6 |
gitlens | eam | 13.1.1 |
prettier-vscode | esb | 9.10.3 |
gc-excelviewer | Gra | 4.2.56 |
vscode-meta | hub | 0.0.1 |
Kotlin | mat | 1.7.1 |
vscode-typescript-tslint-plugin | ms- | 1.3.4 |
shader | sle | 1.1.5 |
code-spell-checker | str | 2.11.1 |
code-spell-checker-russian | str | 2.0.6 |
code-spell-checker-ukrainian | str | 1.0.0 |
vscode-icons | vsc | 12.0.1 |
cocos-effect | Yaj | 0.3.0 |
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
pyindex848:30577860
nodejswelcome1cf:30587006
2e4cg342:30602488
gswce1:30612156
3d0df643:30613357
dbltrim-noruby:30604474
f6dab269:30613381
Hi,
thx for this extension. I checked this plugin out a couple of months ago, and I am sure that I am not crazy and remember that it was possible to pass the configuration for strictNullChecks
via tsconfig
instead of passing it as an argument --strictNullChecks
.
Nevertheless I do not remember, where I read that.
Is it possible to set the strict-config via tsconfig.json
instead of passing each of them as a parameter to tsc-strict
? Or am I crazy?
Hello and thanks for making this cool plugin!
It seems that //@ts-strict
in one file is causing strict errors to show up in all of the others (that don't have //@ts-strict
) right after you switch away from looking at the file that has //@ts-strict
. I have to modify and save a file that doesn't have //@ts-strict
in order for the errors to go away. I'm using the latest webstorm and TS 3.9.7
. Anything I can do to prevent this? Or is this a bug?
Edit: looks like the same thing happens in vscode
Hi, I'm not sure this is really the place to ask, but I'll give it a try. I wanted to ask you if this TS plugin is supposed to support VSCode out of the box or it requires some special configuration.
Here's what I see in VSCode, the following file has not been marked as non-strict into my project
And here's what I see in Webstorm (desired behavior). Error if the file has not been marked as non-strict into my project
Hi,
Thanks a lot for the package, it helps us to add strict mode to the project based on lerna monorepo module by module.
Problem:
During react upgrade to v18 we upgraded next packages as well:
"@testing-library/dom": "9.3.1" -> "9.3.3",
"@testing-library/jest-dom": "5.16.5" -> "6.2.0",
"@testing-library/react": "11.2.7" -> "14.1.2",
"@testing-library/user-event": "14.4.3" -> "14.5.2"
After that, script "typecheck": "tsc-strict --noEmit --incremental false"
runs successfully, despite type errors (IDE still shows errors).
I found out that update of the listed packages to specific versions:
`@testing-library/jest-dom: 6.x.x`
"@testing-library/user-event": 14.5.x
breaks cli check.
We are using package-lock file in project.
Re-generating package-lock breaks cli as well, but there are too much changes to define a problem.
Any thought will be helpful. Thanks in advance
Make tsc --project ./tsconfig.json
show fails (if your plugin is added) without the need to use "yarn tsc-strics".
Having separate CLI to show errors for strict files creates many problems.
Hi,
I'm using this wonderful plugin to start the migration of my company huge codebase to typescript strict.
However it makes VSCode typecheck & intellisense very slow, are you aware of this?
If yes, do you have a potential solution in mind?
It looks like the more opened tab I have, the slower it is.
Thanks in advance!
Arthur
Hi, I am trying to migrate to Typescript + strict mode on a legacy codebase and very interested in this project
This idea is pretty similar in concept to Prettier's --require-pragma
(https://prettier.io/docs/en/options.html#require-pragma)
Prettier is using jest-docblock
internally to parse its pragma and supports multiple comment types
// @format
or
/** @format */
or even
/**
* @format
* @some-other-pragmas
*/
would be great if we can put the @ts-strict
or @ts-strict-ignore
in the docblock as well, so all so-called pragmas are grouped in 1 docblock at the top of a file.
Hello there!
I'm using this wonderful plugin on a legacy codebase. We've just migrated to the latest TS 5.4 and text editors typescript integrations are not working anymore (no error reported, no suggestions, etc) (Intellij, VSCode, Neovim).
Here is a minimal repo reproducing the issue: https://github.com/guillaumewuip/typescript-strict-plugin-5.4-bug/blob/main/src/index.ts
I've investigated a bit, and found a potential fix.
Ensuring that we use local TS version (and not the VSCode one), we can find the related log on tsserver side:
Cannot read properties of undefined (reading 'getSourceFile')
TypeError: Cannot read properties of undefined (reading 'getSourceFile')
at getValidSourceFile (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:146234:32)
at Object.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:146498:30)
at proxy.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript-strict-plugin/dist/plugin/index.js:15:38)
Info 78 [14:38:26.196] TIAdapter:: Scheduling request for: /dev/null/inferredProject1*
Info 79 [14:38:26.197] AutoImportProviderProject: found 1 root files in 1 dependencies in 1.1183749996125698 ms
Info 80 [14:38:26.197] Starting updateGraphWorker: Project: /dev/null/autoImportProviderProject2*
Info 81 [14:38:26.237] Finishing updateGraphWorker: Project: /dev/null/autoImportProviderProject2* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 39.96095800027251ms
Info 82 [14:38:26.237] Project '/dev/null/autoImportProviderProject2*' (AutoImportProvider)
Info 83 [14:38:26.237] Files (1)
/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.d.ts
node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.d.ts
Root file specified for compilation
Info 84 [14:38:26.237] -----------------------------------------------
Info 85 [14:38:26.238] Project '/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/tsconfig.json' (Configured)
Info 85 [14:38:26.238] Files (20)
Info 85 [14:38:26.238] -----------------------------------------------
Info 85 [14:38:26.238] Project '/dev/null/autoImportProviderProject1*' (AutoImportProvider)
Info 85 [14:38:26.238] Files (1)
Info 85 [14:38:26.238] -----------------------------------------------
Info 85 [14:38:26.238] Project '/dev/null/inferredProject1*' (Inferred)
Info 85 [14:38:26.238] Files (55)
Info 85 [14:38:26.238] -----------------------------------------------
Info 85 [14:38:26.238] Project '/dev/null/autoImportProviderProject2*' (AutoImportProvider)
Info 85 [14:38:26.238] Files (1)
Info 85 [14:38:26.238] -----------------------------------------------
Info 85 [14:38:26.238] Open files:
Info 85 [14:38:26.238] FileName: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/src/index.ts ProjectRootPath: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug
Info 85 [14:38:26.238] Projects: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/tsconfig.json
Info 85 [14:38:26.238] FileName: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript-strict-plugin/dist/plugin/index.js ProjectRootPath: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug
Info 85 [14:38:26.238] Projects: /dev/null/inferredProject1*
Perf 85 [14:38:26.238] 2::updateOpen: elapsed time (in milliseconds) 493.6265
Info 86 [14:38:26.238] response:
{"seq":0,"type":"response","command":"updateOpen","request_seq":2,"success":true,"performanceData":{"updateGraphDurationMs":460.96408300101757,"createAutoImportProviderProgramDurationMs":104.01749899610877},"body":true}
Info 87 [14:38:26.238] request:
{
"seq": 3,
"type": "request",
"command": "geterr",
"arguments": {
"delay": 0,
"files": [
"/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/src/index.ts",
"/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript-strict-plugin/dist/plugin/index.js"
]
}
}
Perf 88 [14:38:26.239] 3::geterr: async elapsed time (in milliseconds) 0.2479
Info 89 [14:38:26.240] event:
{"seq":0,"type":"event","event":"syntaxDiag","body":{"file":"/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/src/index.ts","diagnostics":[]}}
Err 90 [14:38:26.247] Exception on executing command delayed processing of request 3:
Cannot read properties of undefined (reading 'getSourceFile')
TypeError: Cannot read properties of undefined (reading 'getSourceFile')
at getValidSourceFile (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:146234:32)
at Object.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:146498:30)
at proxy.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript-strict-plugin/dist/plugin/index.js:15:38)
at IpcIOSession.semanticCheck (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:185769:125)
at /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:185830:14
at MultistepOperation.executeAction (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:184479:9)
at /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:184452:71
at IpcIOSession.executeWithRequestId (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:187516:14)
at Object.executeWithRequestId (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:185514:57)
at Immediate._onImmediate (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/tsserver.js:184452:28)
at process.processImmediate (node:internal/timers:480:21)
Info 91 [14:38:26.247] event:
{"seq":0,"type":"event","event":"requestCompleted","body":{"request_seq":3}}
This validate that typescript-strict-plugin
is probably the culprit.
When calling TS getSemanticDiagnostics
here, it leads to a error thrown from typescript language service instance itself: Cannot read properties of undefined (reading 'getSourceFile')
Looking inside typescript code, we understand this means that the program
variable is undefined
here. Looks like itβs not initialized (anymore?)when the language service instance is created, but only when some methods like are called.
Calling getProgram
just after language service instance initialization fixes the issue.
const strictLanguageService = typescript.createLanguageService(strictLanguageServiceHost);
+strictLanguageService.getProgram()
Is this a valid fix from your point of view? I will push a PR for that - please don't hesitate to redirect me to a better fix if needed, thanks!
Running this on a project that has allowJs on in the tsconfig json and has js files appears to trigger this error. I turned off allowJs and it seems to run.
yarn run v1.10.1
$ tsc-strict
β ¦ Looking for strict files...(node:25319) UnhandledPromiseRejectionWarning: Error: Command failed with exit code 1: tsc --listFilesOnly
error TS5055: Cannot write file '/Users/.../redacted.js' because it would overwrite input file.
...
at makeError (/Users/.../node_modules/typescript-strict-plugin/node_modules/execa/lib/error.js:59:11)
at handlePromise (/Users/.../node_modules/typescript-strict-plugin/node_modules/execa/index.js:114:26)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Object.listFilesOnly (/Users/.../node_modules/typescript-strict-plugin/dist/cli/lib/typescript.js:9:20)
at async getFilesCheckedByTs (/Users/.../node_modules/typescript-strict-plugin/dist/cli/lib/strictFiles.js:28:30)
at async findStrictFiles (/Users/.../node_modules/typescript-strict-plugin/dist/cli/lib/strictFiles.js:34:30)
at async waitWithSpinner (/Users/.../node_modules/typescript-strict-plugin/dist/cli/find-strict-errors.js:36:28)
at async Object.findStrictErrors (/Users/.../node_modules/typescript-strict-plugin/dist/cli/find-strict-errors.js:13:29)
at async run (/Users/.../node_modules/typescript-strict-plugin/dist/cli/cli.js:10:20)
(node:25319) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:25319) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
β ΄ Looking for strict files...
Hi,
coming from an angular project where normal files and test (spec) files are located next to each other it seems impossible to only check the *.ts files and skip the *.spec.ts files. Or did i mess up the configuration.
"plugins": [
{
"name": "typescript-strict-plugin",
"paths": [
"./src/app/folder1",
"./src/app/folder2"
],
"exclude": [
// doesn't work
"./src/app/folder1/**/*.spec.ts"
// doesn't work
"**/*.spec.ts"
// even specifying the files directly seems to have no effect
"./src/app/folder1/subfolder/some-test.spec.ts"
]
}
]
Is ist simply not possible right now?
Thx for your help!
I only care errors. There are too many passed messages, make it difficult to find errors.
I'm running V2. I've followed the README guide for installation. I've run the command update-strict-comments
. Here's the output:
π― Found 2131 strict files
π§ Updated comments in 0 files
However my files are not strict at all!
Here's my tsconfig.json
"compilerOptions": {
"inlineSourceMap": true,
"inlineSources": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"pretty": true,
"lib": ["ES2020", "dom"],
"module": "CommonJS",
"moduleResolution": "node",
"target": "ES2018",
"declaration": true,
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"incremental": true,
"esModuleInterop": true,
"strict": false,
"plugins": [
{
"name": "typescript-strict-plugin",
"paths": ["./src"]
}
]
}
We use the old yarn and run the check in parallel with the build. But the output of the plugin breaks the nice order we want to see at build time.
Maybe add a flag that disables output to the console if there are no errors? I think that it would be useful for many.
Hi!
Is there a way to get errors in IDE?
README says "They will show errors in your IDE but they won't appear during compilation", but I didn't find a way to get them.
(I am using vscode).
Thanks in advance!
I'm setting up build-time linting for a project (ie. tsc && tsc-strict) and noticed that ts-expect-error will always fail linting if the expected error is due to strict typing because tsc will think that there's no expected error (and say that the ts-expect-error should be removed) while tsc-strict will see the error. Any ideas for how to fix this? Perhaps tsc-strict could do the linting for all files or maybe there's a way to have tsc skip strict files?
For now, the best solution I can think of is to just use ts-ignore instead.
Sorry this is just a question
I found ts-strict-ignore
branch and it looks interesting
When will it be released?
Thank you!
First of all, this is a great plugin, thanks for creating and maintaining this project.
My organization maintains a monorepo whose code has evolved over a number of years from vanilla js
-> FlowJS
-> now Typescript
. That said we have been working to correct and improve the codebase incrementally as the code is owned over a large number of developers -- this tool fits our use-case exactly to do these improvements incrementally.
So our monorepo structure (with respect to typescript) looks like:
.
βββ frontend
β βββ tsconfig.json
βββ tsconfig.json
The first level one is used only at this point for tooling resolution (vscode language server, etc), and our build only occurs at the second level tsconfig.
When trying to add --project ./frontend/tsconfig.json
I noticed that the plugin was not able to find our typescript project. Doing a bit of code spelunking it appears that the root directory used is the root location for the plugin even if specified within a nested tsconfig.
I forked the project and have a set of minimal changes which would add non-root project support (via the tsc --project flag), wondering if this would be a useful addition to your codebase?
I have the diff of changes here in this branch: master...neenjaw:typescript-strict-plugin:add-non-root-project-support
Usage in action after the proposed changes:
running
tsc-strict
beforeupdate-strict-comments
β webapp git:(strictify-ts-plugin) β yarn tsc-strict --project ./frontend/tsconfig.json
# => list of many files with errors.
π₯ Found 9008 errors
running
update-strict-comments
β webapp git:(add-strictify-ts-plugin) yarn update-strict-comments --project ./frontend/tsconfig.json
π― Found 7217 strict files
π§ Updated comments in 2223 files
β¨ Done in 37.29s.
running
tsc-strict
β webapp git:(strictify-ts-plugin) β yarn tsc-strict --project ./frontend/tsconfig.json
π― Found 4994 strict files
π All files passed
β¨ Done in 35.33s.
Hi I love the idea of your plugin. I'm trying to get it to work in my monorepo, which uses Nx.dev.
Here's how you can get a repo locally to test with:
npm i -g yarn && \
rm -rf ~/nx-demo && \
cd ~/ && \
npx create-nx-workspace nx-demo --packageManager=yarn --style=less --nx-cloud=false --interactive=false --preset=empty --linter=eslint && \
cd nx-demo
I currently get this error
Error: Command failed with exit code 1: tsc --showConfig
error TS5081: Cannot find a tsconfig.json file at the current directory: C:/p/nx_test.
Many thanks!
I'm using yarn workspaces, and in each package I have my own tsconfig that extends the root tsconfig. The issue is, this plugin doesn't seem to work properly regardless if I add the plugin to the nested tsconfig, or the root tsconfig.
When adding the plugin to the nested tsconfig and using the paths
option, the paths resolve differently between the plugin and the CLI.
./src
(targeting src
folder relative to nested tsconfig), the plugin doesn't work, but the CLI finds the strict files properly./nested/src
, the plugin works now, but the CLI is not able to find any strict files.The issue here, I believe, is that the way I'm invoking tsc-strict
is via the yarn workspace
which executes it inside the nested directory, whereas the plugin is taking the entire project into account. So the paths resolve differently.
To solve the above issue, I moved the plugin from the nested tsconfig to the root tsconfig instead and started invoking tsc-strict
at the root instead. But the nested tsconfig still seems to be interfering. The plugin simply does not work unless the nested tsconfig is removed/renamed, even though that nested tsconfig extends the root config. Is it that the plugin doesn't properly grab the paths
option from the extended tsconfig?
Also, not sure if related, but running tsc-strict
, files are found but they all "pass" which is definitely wrong. When the plugin was in the nested tsconfig, it found plenty of strict mode errors. Removing/renaming the nested tsconfig does not fix this so not sure what is going on here.
Even though I have paths in my config, the plugin still checks every directory.
You can test it on sample-project in the repository with tsconfig setting:
"plugins": [ { "name": "typescript-strict-plugin", "paths": ["./src/main.ts"] } ]
Similiar story is with folders in paths, e.g. "./dist", still checks files in ./src
I have the following in my ts config file:
"strict": false,
"plugins": [
{
"name": "typescript-strict-plugin"
}
],
I have a TS file with the following:
const age = myCollection.find(x => x.name === targetName).age;
the file does not have a // @ts-strict-ignore
comment in it.
My IDE correctly flags the issue as Object possibly undefined
. when I build, it does not create an error, and the linter passes as well.
I want to prevent a file like this from being commited using a git commit hook. Currerenty our hook runs eslint via lint-staged but I wonder if it could run tsc-strict
just on the staged files?
The plugin works fine with TS 5.1.6, but upgrading to 5.2.2 with the plugin enabled, completely turns off any TS errors in the IDE (not only strict mode errors - all others as well). This happens both in VSCode and Webstorm.
Dropping to 5.1.6 makes the plugin work again, and removing the plugin makes 5.2.2 show "normal" (non-strict) errors in the IDE.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.