Repository navigation
Add TypeScript type checking - #6862
Conversation
|
@mohsen1 the ‘_this’ error looks like a bug, mind filing this on the TS side. |
|
This was discussed? |
|
@montogeek I don't believe it was discussed before. I'm using Webpack to test the idea of using TypeScript for type checking large JavaScript projects. Would love to finish it up and a complete case study. Is this is something worth merging if I can complete it? I'm not sure! I would say yes but it's up to owners obviously. |
|
This is interesting. I also wanted to try using typescript as linter but had no time for this yet. Please fix any errors you find in separate PRs so we can merge them independently and this PR doesn't get filled up with fixes. Instead it should only contain the ts-as-linter stuff. Error 1 seem to be really broken, Error 2 and 3 are also true but have no negative effect... |
| @@ -103,6 +106,7 @@ | |||
| "pretest": "npm run lint-files", | |||
| "lint-files": "npm run lint && npm run schema-lint", | |||
There was a problem hiding this comment.
call the typescript linting here, to add it to the CI
There was a problem hiding this comment.
Will do once number of errors is reduced. The lint bot comments will pollute this thread if I do. See #6869
|
would it be possible to add (stricter) interfaces as additional I only want to know if this is possible. The first PR should only add the infrastructure. |
|
It is possible, but the type definitions there are not used to validate the contents of |
|
One could always add |
|
You can, it's just that that still doesn't bring any relationship between the |
|
It's sad that it doesn't validate the content ifself, but we can still use it to describe the public interface of these classes. |
|
@mohsen1 can you point me to examples like |
|
I got lazy and accepted a lot of TypeScript "Quick FIx" suggestions so its not the best change list to fix all issues but there are some interesting things in that PR! if you're onboard with enabling TS as a linter in Webpack I can take a more incremental approach and make smaller PRs against this branch and go over issues one by one. |
|
@sandersn filed a ticket for that issue as well |
|
Future PRs could now add types to stuff by using jsdoc. I guess it would be useful to have types on the basic types. |
| @@ -0,0 +1,62 @@ | |||
| { | |||
| "compilerOptions": { | |||
| /* Basic Options */ | |||
There was a problem hiding this comment.
Can we get rid of the comments?
There was a problem hiding this comment.
It's a JSON5 file, but can't use .json5 🤷♀️
There was a problem hiding this comment.
It's an issue with Github. Commented JSON is fine. Even Mr @douglascrockford is cool with it ;)
There was a problem hiding this comment.
I do not know what JSON5 is, but whatever it is, I am not cool with it.
There was a problem hiding this comment.
@douglascrockford How about https://hjson.org/? 😄
There was a problem hiding this comment.
oh my, way to go on using the ad verecundiam in public @mohsen1
There was a problem hiding this comment.
@douglascrockford Re I do not know what JSON5 is:
The JSON5 Data Interchange Format (JSON5) is a superset of JSON that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from ECMAScript 5.1.
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
| this.errors.push(new ModuleError(this, error)); | ||
| }, | ||
| exec: (code, filename) => { | ||
| // @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'. |
There was a problem hiding this comment.
normal module is not precisely implementing native module. This is why ts ignore directive is here.
We can use jsdoc @implements to actually resolve it but then this class needs some additional members to satisfy normal module.
There was a problem hiding this comment.
This should not block merging this pull request though..
|
It looks like this Pull Request doesn't include enough test cases (based on Code Coverage analysis of the PR diff). A PR need to be covered by tests if you add a new feature (we want to make sure that your feature is working) or if you fix a bug (we want to make sure that we don't run into a regression in future). @mohsen1 Please check if this is appliable to your PR and if you can add more test cases. Read the test readme for details how to write test cases. |
|
@sokra Thanks for fixing those issues. Next big task is to add complete JSDoc coverage. Once we have that we can enable the strict mode. @TheLarkInn We'll need community support to add JSDoc coverage. It would be nice if you can do what you did for converting to ES2015 by involving the community. It's lots of work and we need help! Lets merge this! 🎉 |
|
@mohsen1 note that you can turn on strictNullChecks without any of the other strict flags. In Typescript's test that compiles the npm-distributed version of webpack, we only see 28 "Object is possibly undefined errors". |
|
@mohsen1 thank you so much for this. Let's land it. |
|
@mohsen1 I think it would make sense to create issues that would involve turning each of the strict checks on and implementing the coverage required for them now and contributors can tackle these bit by bit. |
|
Well done @mohsen1!!! |
|
Good job! ❤️ |
Summary
Wanted to try using TypeScript with
allowJsandcheckJsto see if it can improve code correctness.Webpack is a good case study for using TypeScript compiler on JavaScript projects. This is still a work in progress and I'm not sure if we can use TypeScript to check for errors without any code modifications.
Issues in TypeScript and DefiantlyTyped
_thisas a variable name.Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference.class Foo {}; let f = new Foo(); f.bar = 1undefinedas value in class constructor to surpass those errorsAdd class member initializations for multiple classes #6987@types/tappabletypes are not accurateClass 'Module' defines instance member property 'identifier', but extended class 'ExternalModule' defines it as instance member function.Add _nodeModulePaths to node Module class DefinitelyTyped/DefinitelyTyped#24526Add deprecated process.bindings to node.js DefinitelyTyped/DefinitelyTyped#24521declarations.d.ts// @ts-ignoredirectivemodule.exportsassignmentsvm.runInThisContextis wrong. it does not accept string filename for optionsstringfor iterator offor..ininObject.keysIssues found in Webpack by TypeScript
compilationDependenciesinCompilation(Fix: Initialize compilationDependencies in Compilation as undefined #6885)WebAssemblyImportDependencyRemove extra argument from WebAssemblyImportDependency constructor call site #6882JavascriptGeneratorhas no constructor but getting arguments Remove extra argument passed to JavascriptGenerator constructor #6881hideStackis being appended toErrorclass.dependencyTemplatesHashMapweak map Use a Map for dependencyTemplatesHashMap instead of a WeakMap #6922cacheMergedwill not work with more than 2 argumentsWhen this is complete?
This is going to be a lot of work to get it to the finish line and I'm not sure if it is inline with the project goals. This is why I'm opening the pull request early. Hoping we can overcome all of those TypeScript issues and make use of TypeScript compiler in Webpack! 🙏
Only comment changes
This pull request on its own should not hav any code changes. TypeScript type checking should be non-invasive and should not make users to change their code. At most, changes should be comments only. If any code change is necessary due to bugs or TS limitations, we are going to propose and merge them in separate pull request.
TypeScript 2.9
The amazing TypeScript team have fixed many issues with the compiler when checking JavaScript code. Those changes are currently (April 11) in the nightly builds of version 2.9. We can merge while depending on nightly version but it would be nicer to depend to
betarelease in master. We should eventually depend on a stable release.@TheLarkInn @DanielRosenwasser @mhegazy