Skip to content
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

Provide ambient types or TSify some js[x] files. #7114

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

na9da
Copy link
Collaborator

@na9da na9da commented Apr 26, 2024

What this PR does

Currently, running tsc from an external library like a plugin fails with many ... element implicitly has type "any" errors. This is because tsc will not type check js/jsx modules from external libraries in node_modules. These errors can be suppressed by turning off noImplicitAny option, however this is pretty unsafe.

This PR tries not to change any functionality, instead we typify just enough files so that tsc will succeed without having to add any extra configuration. We make the following specific modifications:

  • If it is trivial, we convert .js[x] files to .ts[x] and make necessary changes so that it type checks
  • For non-trivial .js[x] files, we create an ambient .d.ts file with type signatures for all the exports
  • Upgrades markdown-it and linkify-it so that we can import their ESM versions and typings.

Test me

Please just do a random test adding different catalog items, via catalog explorer, web url and drag-n-drop, open feature info panel, charts etc.

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist) Fixed broken specs.
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

@na9da na9da changed the title Provide ambient types or TSify some js/jsx files. Provide ambient types or TSify some js[x] files. Apr 26, 2024
"lodash-es": "^4.17.11",
"markdown-it": "^11.0.0",
"markdown-it": "^14.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this in my pile of security fixes, this fixes CVE-2022-21670.

Copy link
Member

@steve9164 steve9164 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just need to confirm the DisclaimerHandler changes.

Comment on lines 1 to 8
export default function arrayContains<T>(array: readonly T[], value: T) {
for (let i = 0; i < array.length; ++i) {
if (array[i] === value) {
return true;
}
}
return false;
}
Copy link
Member

@steve9164 steve9164 May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this (only used in 1 place in terriajs) and replaced with Array.prototype.includes.

@@ -449,8 +447,6 @@ export default class ViewState {
}
);

this._disclaimerHandler = new DisclaimerHandler(terria, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used in v7 for showing catalog item initial message. In v8 this is handled here:

if (this.shouldShowInitialMessage) {
// Don't await the initialMessage because this causes cyclic dependency between loading
// and user interaction (see https://github.com/TerriaJS/terriajs/issues/5528)
this.showInitialMessage();
}

!e.dataTransfer.types ||
!arrayContains(e.dataTransfer.types, "Files")
) {
if (!e.dataTransfer.types || !e.dataTransfer.types.includes("Files")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made this change to remove arrayContains

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants