-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[WIP] Create Typescript declarations for Mixxx Javascript APIs #2636
Conversation
Add typescript declaration file for built-in Javascript APIs to improve DX when creating mappings.
To clarify, IDEs can use this with plain JS? I don't want to require TypeScript, and probably don't want any transpiled scripts. |
Generally, TS was designed to be compatible with JS. So even TS libraries can be used with plain JS because the TS libraries get distributed as JS and matching declaration files. So every IDE that understands So, yes. IDE's should be using this with plain JS since typescript was designed with that in mind. |
Can we use this file for linting with pre-commit? Can eslint read this file? |
Not without additional tools unfortunately, theoretically, one could run |
pre-commit installs dependencies automatically. I think it's available on npm, so it should work |
Well, that said, the just because the tsc would pass, it doesn't guarantee that the APIs are used correctly. eg some functions expect integers but JS/TS only has a number type. It would also still be possible to have typos in the group or key strings... So it would only still catch a small subset of potential errors. |
Needs a bit more work, but: Swiftb0y#2 |
If we're telling mapping developers to use pre-commit for eslint anyway and it's no more trouble to use this for linting, I don't see why not. |
Using tsc for linting would also require a definition for all the other types exposed by QJSengine. This would in turn require another handwritten typescript definition file just for that. I think the amount of effort required to make it work is not worth the linting capabilities... So I'm against introducing tsc as a pre-commit hook! |
So it isn't possible to tell tsc to only check defined types and ignore everything else? |
afaik tsc will throw errors when it encounters symbols which are not defined (even when not running in strict mode). I think you can still use |
Are there any interpreter specific types except the stuff in |
Not right now afaik, its still a case where tsc is enforcing arbitrary boundaries... I'll still try to make it work for testing purposes, but I am unsure about any consequences overly strict pre-commit rules (such as relying on tsc not complaining) have on the DX (the thing this PR is actually trying to improve). |
This folder structure is required so we can use the ts declaration for linting with TSC.
In some methods, its still allowed to pass expressions (in the form of a string) which evaluate to functions instead of passing the function-symbol directly.
So I got linting with tsc to work... the next step forward would be to write declaration files for the entire API (so also other scripts such as |
Sure |
Don't forget to document on the wiki how to configure some text editor to take advantage of this! |
Of course. Intellisense/vscode use it automatically. What other editors should I test? |
So imagine I have my script in a dedicated repo, how do I use this? |
Depends on what you would like to use it for... If its just supposed to be used for code completion, there has to be a copy of the file present somewhere in your repo as well. If used for linting, there has to be the specific folder structure present and tsc needs to be pointed to the |
I have also made a d.ts file for Mixxx. I only implemented the things I really used in the mapping. What stood out to me when comparing the definitions was that I have a function |
Yes. I actually forgot that there was an
Autocompleters are usually very lenient about what is what, so it doesn't matter to them whether the functions are contained in a namespace or an interface but from the pov of tsc, it would matter. If an interface is used, tsc will essentially think You also use I used typescript for writing a project I created for a paper for school. Took me about 4 months but it unfortunately never really saw the light of day. Still, I used it enough to know that I don't really like using it but its ambient declaration are good for things like improving developer declaration and catching typeerrors during compile time. |
This PR is marked as stale because it has been open 90 days with no activity. |
This PR is superseded by #4759 which is merged now |
Yep, ty |
Discussion: https://mixxx.zulipchat.com/#narrow/stream/109171-development/topic/TypeScript.2Ffuture.20mapping.20system
Most code-completion tools can read typescript declaration files and JsDoc annotations.
This would be a great DX improvement for new people trying to create a new controller mapping.
I'm planning to add the JsDoc annotations soon, as well as creating declarations for midi-components and common-controller-scripts. I just wanted to create a PR now so someone can verify I didn't miss anything so far.