-
Notifications
You must be signed in to change notification settings - Fork 26
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
Convert to TypeScript #187
Conversation
This converts the use of `import =` and `export =` to ESM syntax. The ESM syntax is compiled to CJS.
This is a breaking change as |
Also rename `TransloaditClientOptions` to `Transloadit.Options`.
Do you want to wait until Mikael is back to give the final okay, or move ahead already? |
I think we can wait for Mikael to review this. |
we can probably already set something up for auto-releases? |
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.
very nice stuff!
{ | ||
"exclude": ["src"], | ||
"references": [{ "path": "./tsconfig.build.json" }], | ||
"compilerOptions": { |
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.
I think we should "extends": ["@tsconfig/strictest"]
as it adds some nice checks (or we can just pull out those rules from that file and put them in ours). however we could do that in a future PR.
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.
I see some nice options there, but also some options I really dislike.
I could enable exactOptionalPropertyTypes
, noPropertyAccessFromIndexSignature
, and noUncheckedIndexedAccess
, but all other options are more either undesired or more appropriate as lint rules.
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.
I agree that some rules are better covered by eslint (because eslint is more flexible in that you can disable rules per-line, while typescript cannot). however I still think that:
isolatedModules
I think it's recommended to enable this in order to enforce writing typescript in a style that is compatible with external tools likeesbuild
,tsx
etc. tsx even recommends enabling it.esModuleInterop
: from my research it's generally recommended to set this totrue
, andtsx
also recommends it.skipLibCheck
recommended by TypeScript to set totrue
noImplicitOverride
which eslint rule covers this?noImplicitReturns
eslint has consistent-return, however they recommend that we instead use the typescript rule.
what's the reason you really dislike these typescript rules?
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.
isolatedModules
is needed when compiling the TypeScript with tools other thantsc
.vitest
is also one such tools, so we should probably enable it indeed. Better would be to useverbatimModuleSyntax
, but that’s not supported with Vitest apparently.esModuleInterop
is implied by"module": "node16"
. We don’t need to define it explicitly. Note that this option is risky for libraries (TypeScript generated invalid types ifesModuleInterop
is enabled microsoft/TypeScript#52779). The solution is to useverbatimModuleSyntax
, which we can’t because of Vitest.skipLibCheck
is basically a huge@ts-ignore
applied to all.d.ts
files. This is useful if you have dependencies that have type errors. I prefer to disable this, as that helps identify possible compatibility issues with other dependencies. Whether or not to enable this, is subjective.noImplicitOverride
requires TypeScript specific syntax for overriding methods. I slightly prefer to not rely on that. In my experience it’s barely ever relevant though. I haven’t given it that much thought. I could see its value.noImplicitReturns
is a stylistic choice I just don’t like. I pretty strongly prefer the exact opposite style (unicorn/no-useless-undefined
). I combine this with explicit type annotations (@typescript-eslint/explicit-function-return-type
). That’s a good idea for libraries anyway, as it gives more control over the types you publish.
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.
esModuleInterop
is implied by"module": "node16"
.
ok, let's remove it.
skipLibCheck: false
I had problems with it before, where some library had type errors and i couldn't compile because of that, and i believe it's slower. but if it works with skipLibCheck: false
now, then i guess why not. feel free to set it to false.
noImplicitOverride
requires TypeScript specific syntax for overriding methods. I slightly prefer to not rely on that. In my experience it’s barely ever relevant though. I haven’t given it that much thought. I could see its value.
I also don't rely on this rule very often because i rarely use classes / oo & inheritance in javascript, but when i do, i think it has benefits because I can get an error if some library that I depend on change their signature of an inherited class prop without me knowing. and typescript already has a bunch of other non-js compatible syntax so i don't see any drawback with that.
noImplicitReturns
is a stylistic choice I just don’t like. I pretty strongly prefer the exact opposite style (unicorn/no-useless-undefined
). I combine this with explicit type annotations (@typescript-eslint/explicit-function-return-type
). That’s a good idea for libraries anyway, as it gives more control over the types you publish.
Fel free to remove the rule. As for @typescript-eslint/explicit-function-return-type i'm not sure how to make it only apply to public functions, because i don't like having to manually type every internal function
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.
I applied this feedback and also applied the new options to tsconfig.json
.
I also removed noPropertyAccessFromIndexSignature
, as it’s a stylistic choice our code currently doesn’t adhere to.
Instead of coercing a lot of checks into a single boolean, we now throw early.
This reverts commit 2e8072d.
did you run |
for easier debugging
"exactOptionalPropertyTypes": true, "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true,
found the bug in the tests have also enabled the rules
|
this is odd. |
I've now also added the rules
but we can discuss it if you don't agree |
I'm seeing a test failing locally though, it's very strange:
|
I also failed to run one integration test locally, but it does work on CI. That issue existed before I got involved. I have no idea what causes it. |
Our code is not compatible with this.
This broke the integration tests in the main branch, but I’m not sure why. Also why don’t we run those for pull requests? |
It only failed for node22.3.0 https://github.com/transloadit/node-sdk/actions/runs/11290300021 so it might be a flake We don't run in for all pull requests because
|
The latest run seems to have succeeded again. So at least this PR didn’t cause breakage. |
This converts the code base from JavaScript to TypeScript. The tests are failing because of a reason I don’t understand. It’s complaining about the use of TypeScript’s CJS syntax.