-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Fix typing error when consuming maplibre-gl with TypeScript compiler … #2600
Fix typing error when consuming maplibre-gl with TypeScript compiler … #2600
Conversation
I think if we want to guard against a problem like this in the future, maybe it would be good to add a dummy project that references the built dist folder and is configured |
Can we set yhe tsconfig somehow to guard for this? |
I think having strict: false in the tsconfig means it specifically won't complain about this? Setting it to true is going to open a big can of worms though. That's why I mentioned adding a separate dummy project just to ensure something else with that set can consume the typings. |
Can't we just add strictNullCheck? Would that solve this specific case and guard for that only as a first step? |
Happy to try it and see what happens. I'll report back. |
THANKS!! |
Well, adding |
Interesting, So how come the line you fixed here is the only one needed in order to solve this issue? |
Adding So, all I can figure out is that TypeScript must be performing different (less strict) checks on dependencies (.d.ts files?), but when building a project against these typings, this return type mismatch is still something it cares about. I'm not sure why though. |
I don't understand :-( there are other places in the same file with the same problem, how come only this affects dependent libraries... |
I agree wholeheartedly. This is the only occurrence of getDefault() not matching the base class's typings, but the parameters to set() not matching and still working is strange. This issue is blocking me from using 3.x, but I do want to see a long-term solution. What do you think of getting the typings to work, and then we can work on adding a dummy project with As an aside, I cannot simply turn off |
Let me think about it, maybe I can do an effort to clean this project and not introduce a "weird test". |
I'd also be happy to work toward |
I'm wondering if this exists because of a combination of this open TypeScript issue, having strict null checking turned off, and explicitly declaring the return type of the subclass's function to include null. Also, when I have the maplibre-gl-js project open in vscode and then open the generated .d.ts file, it underlines the line in red and shows the exact same error! |
I found something even more strange. If I change the getDefault() function to this:
Everything works. The typings are generated "correctly" ( |
I've added strictNullCheck and got tons of errors. |
I started a branch and opened a PR. |
I think i know why this is the only issue the we see. |
Thanks very much! I'll jump in as soon as I can.
That makes sense to me too. Have you verified if that's the only public |
Can you check if adding the following files help future proofing this situations:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"strictNullChecks": true,
},
"include": [
"dist/maplibre-gl.d.ts"
],
"exclude": []
}
From a small test I made this shows the error before fixing it, and the error is gone after the fix. |
This works for me! I also agree with your assessment. However, I did notice a problem with typecheck that had me confused for a minute. I'll comment on your PR though. |
Simple typing change that closes #2588. Note that the removal of
| null
makes the class consistent with all others in the file. With this change, I'm able to consume the library from a project withoutstrict: false
set in its tsconfig.Launch Checklist
CHANGELOG.md
under the## main
section.