-
Notifications
You must be signed in to change notification settings - Fork 18
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
Type conflicts with lib.dom.d.ts #72
Comments
Hello @HeavenVolkoff, if you have good results with it then you can already make a pull request from your branch, best is to add a note about the I like your suggestion, but what do you think about adding an new The
To keep the command from getting too complex we should concentrate on the most important for now, if there is a need for more configuration options we can always introduce them, so e.g. I would make esbuild to the default bundler and not ask for another. The init command then does the following:
What do you think? |
You mean the Text(D)Encoder implementation? If so, I can open a PR with the global definition commented out and a README note mentioning the problem about
I agree, that is a better approach.
Agree, I also use esbuild on my gjs projects.
Currently, I am using
The rest of logic seems fine with me. However, I still think the As soon as I have some more free time, I will try to start implementing this, if that is ok with you? |
@HeavenVolkoff Jea, feel free to implement that :) |
@HeavenVolkoff Perhaps I have now also misunderstood something, if the tsconfig is set correctly, then the types for |
Solution for #72 + Add type definitions for Text(D)Encoder
@JumpLink @HeavenVolkoff #86 introduces an interactive prompt which asks whether DOM types should be ignored if the generator believes that the DOM library is enabled in tsconfig. I can't find a way to disable this prompt, or non-interactively answer it with "no". But I'd like to, because the way the typescript configuration is checked doesn't really work for multi-project setups, where the top-level tsconfig.json typically only has references to subprojects, and the subprojects then have their own tsconfig which inherit compiler options from a shared base config. In other words, the actual compiler flags aren't reachable from my out directory. I don't think it's a good idea to prompt interactively in this situation (no code generator that's supposed to be used in some kind of build system should ever prompt, in my opinion); I'd prefer if I only got a warning, which advised to change the configuration, and had a way to suppress that warning. Would you accept a pull request to this end? |
@swsnr it is possible to preemptively answer this, and any prompts, with command line arguments or entries in the config file. In the case of the DOM lib prompt there is About the multi-project setup, the currently implemented logic should work in those cases. Would it be possible for you to share a simple example of this not working, maybe there is a bug in the @JumpLink maybe a check should be implemented for when ts-for-gir is executed in a non interactive environment so that it either assume some default behaviour or raise an error instead of prompting. |
@HeavenVolkoff And I think that's a pretty common situation in a multi-project build of the following schema: One top-level I think that's a pretty standard setup, to be found in e.g. the typescript compiler repository itself. In this layout ts-for-gir will only see the top-level I don't think that this is an exotic setup, but it's not supported by ts-for-gir now, because I cannot force |
@swsnr you are right, About ts-for-gir interacting with tsconfig, IMHO I think it is necessary, considering one of its major use cases is for the generated types to be used for type checking, and most (if not all) currently used linters interact with tsconfig for figuring out the runtime environment and available global symbols... Regarding the tsconfig discovery logic, currently it is impelemted by searching for the first tsconfig file in the given output directory or any of its parents, and the lib that is used to parse tsconfig should support |
I think it's fundamentally wrong, because it inverts facts and potentially hides type errors. The gjs environment is what it is regardless of what I have in my I think ts-for-gir must always generate complete types, and tsc must fail if I have conflicting types. |
Or am I misunderstanding the meaning of "noDOMLib" and its interaction with the DOM lib types specified in tsconfig? |
@HeavenVolkoff So far, user interactions have been prevented by setting
@swsnr Your argument makes sense, and therefore it should be the default behavior. However, currently I am working on a wrapper to replicate the DOM API in Gjs, and it is possible that I still need the option to be able to use the DOM types for it. |
Hello,
Currently, the type definition for the global
console
is commented out in:https://github.com/sammydre/ts-for-gir/blob/979d2a016f182ca54f14047483d2b29cac126ade/templates/Gjs/index.d.ts#L201-L202
This is due to conflicts with the global definitions shipped with typescript, that are used by most IDEs (such as VSCode):
https://github.com/microsoft/TypeScript/blob/93f2d2b9a1b2f8861b49d76bb5e58f6e9f2b56ee/lib/lib.dom.d.ts#L17750
However, this results in gjs code being linted with
lib.dom.d.ts
type definitions, which is not ideal, as gjs implementation of those interfaces has slight differences and incompatibilities with the DOM implementation present in browsers, and the vast majority of the DOM API is not implemented in gjs (and probably will not be, according to #265).This can be worked around by using a custom tsconfig.json / jsconfig.json that doesn't contain DOM in the lib property:
So far in my tests with VSCode, this prevents the
lib.dom.d.ts
from being used, and allows the local definitions generated by ts-for-gir to work without error, even withconsole
commented out and my, yet not upstreamed, additions of typing definition for gjs recently implemented Text(D)Encoder .IMHO, ts-for-gir could attempt to solve this automatically. The logic I am considering would be something along the lines of:
tsconfig.json
than generate one following the example abovetsconfig.json
, check if DOM is included in thelib
property:The text was updated successfully, but these errors were encountered: