-
-
Notifications
You must be signed in to change notification settings - Fork 28
Add typescript #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add typescript #122
Conversation
|
New dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No new dependency issues detected in pull request Bot CommandsTo ignore an alert, reply with a comment starting with Pull request alert summary
📊 Modified Dependency Overview:
🚮 Removed packages: [email protected], [email protected], [email protected] |
tsconfig.json
Outdated
| "allowJs": true, | ||
| "checkJs": true, | ||
| "resolveJsonModule": true, | ||
| "skipLibCheck": true, | ||
| "target": "es2015", | ||
| "moduleResolution": "node", | ||
| "noEmit": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case you didn’t know: At some point you probably want to make the typechecking more comprehensive, especially adding "strict": true. More candidates:
"strict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"useUnknownInCatchVariables": trueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I knew I didn't check for much (because I first want to get rid of the configuration-related errors), but I didn't know exactly which things I needed to be enable. This saves me some times 😊
If you have more tips and candidates, I'll take them. I think there was one about implicit any for instance, which I'll try to find at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strict is a shortcut for enabling a bunch of other options, including noImplicityAny. I couldn’t find the exact list of options in TypeScript’s documentation, but I found this in a blog post:
noImplicitAny
noImplicitThis
alwaysStrict
strictBindCallApply
strictNullChecks
strictFunctionTypes
strictPropertyInitialization
I went through the elm-watch tsconfig.json, and the last strictness related one seems to be:
"noUncheckedIndexedAccess": true,But when adding TypeScript to an already existing code base it might make sense to enable one thing at a time so you don’t drown in errors, before you have even learned how to deal with many of them.
The final level is to bring in typscript-eslint. Then you get close to Elm level type system confidence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks :)
2442b74 to
7fdb001
Compare
|
I found solutions to some of these last issues, and ts-ignored the rest :( |
|
@jfmengels Try adding |
|
Nope, I was wrong about For me, this works: const { default: elmToolingCli } = require("elm-tooling");
const { default: getExecutable } = require("elm-tooling/getExecutable");EDIT: It typechecks. But does it work at runtime? Need to check. EDIT2: Nope. Why is TypeScript so hard to get right with dependencies… |
Yes, I went through the same cycle you just went through 😅 |
|
Oh well, I must have misunderstood something and made some mistake in elm-tooling. I’ve only tested it with pure JS (both So maybe just go with |
|
Found a workaround if you really want typechecking for those calls: const elmToolingCliImport = require("elm-tooling");
const getExecutableImport = require("elm-tooling/getExecutable");
const elmToolingCli = /** @type {typeof elmToolingCliImport["default"]} */ (
/** @type {unknown} */ (elmToolingCliImport)
);
const getExecutable = /** @type {typeof getExecutableImport["default"]} */ (
/** @type {unknown} */ (getExecutableImport)
); |
|
Thanks, I'll keep it as is for now I think, but happy to know that your comment will be here if I change my mind 😄 |
The purpose of this PR is to use TypeScript to type-check the JS code of the CLI, to feel more at ease when changing that part of the codebase, which todays feels quite scary to be honest.
It's apparently quite do-able to have TS understand type annotations through JSDoc comments, so I think I want to try that instead of converting files to
.ts. If that works out well, then we can skip the transpilation phase, which will keep it pretty smooth to run the CLI in development mode (no need to wait for TS to compile the project).We can potentially also use this to publish
.d.tsfile, in case someone wants to depend on the JS API of the tool (like elm-tooling/elm-language-server#942). I imagine this would help, but I could be wrong.Status of the PR
I'm finding a bunch of issues that I add to the main branch, but this PR is not ready yet.
First of all, I have a large number of problems that TS reports that seem like configuration errors.
Second, I still need to add TS to the test script so that we're made aware of TS errors.
In a separate PR, we could then remove Flow.
I'd appreciate any help with this work and/or with adding type annotations to the JS codebase (better done in separate commits).