Skip to content

Conversation

@43081j
Copy link
Collaborator

@43081j 43081j commented Jan 6, 2025

Removes our override such that any is no longer allowed, and replaces usages of it.

@fb55 this uncovered a curiosity:

the Updating node source code location (GH-314) test was basically asserting that you can have a custom source code location setter. i.e. you can have your own location shape

however, we have a strong type for Location and all tree adapters are required to return an ElementLocation from getSourceCodeLocation (which itself is a Location).

so while we do let you set whatever you want in setSourceCodeLocation, it doesn't make much sense to set anything that isn't a Location, as you need to get that back out in getSourceCodeLocation anyway.

tldr i think the test and the use case made sense way back, but has lost its meaning as we've strengthened types

Removes our override such that `any` is no longer allowed, and replaces
usages of it.
Copy link
Collaborator

@fb55 fb55 left a comment

Choose a reason for hiding this comment

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

Very nice!

Copy link
Collaborator

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

As for “so while we do let you set whatever you want in setSourceCodeLocation, it doesn't make much sense to set anything that isn't a Location, as you need to get that back out in getSourceCodeLocation anyway.”

This project predates typescript, and also not every javascript user uses typescript. So would an alternative approach also be possible: to make the types match javascript?

Not everyone will understand the usage of `never` here, so we can
continue using `any` instead and ignore the linter.
@43081j
Copy link
Collaborator Author

43081j commented Jan 7, 2025

This project predates typescript, and also not every javascript user uses typescript. So would an alternative approach also be possible: to make the types match javascript?

the parser assumes getNodeSourceCodeLocation returns an ElementLocation. this is concrete whether you use types or not

similarly, update/set are passed an ElementLocation

these are not in question and have the right types. however, sourceCodeLocation could technically be anything (on a node)

so, for this test to work as it used to, it'd need its own Node type which has a different sourceCodeLocation (i.e. its nothing to do with our non-test types)

@43081j 43081j merged commit 3844827 into master Jan 16, 2025
11 checks passed
@43081j 43081j deleted the no-any branch January 16, 2025 16:43
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.

5 participants