Skip to content

types: ensure location attrs exists #13

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

Conversation

ChristianMurphy
Copy link
Member

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

TypeScript can't quite infer that location.attr is not undefined from the loop, this gives TS an extra hint.

@ChristianMurphy ChristianMurphy added the ☂️ area/types This affects typings label Mar 4, 2022
@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 4, 2022
@@ -286,7 +286,7 @@ function createLocation(ctx, node, location) {
let key

for (key in location.attrs) {
if (own.call(location.attrs, key)) {
if (location.attrs && own.call(location.attrs, key)) {
Copy link
Member

Choose a reason for hiding this comment

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

There is no good reason for this code inside the loop (other than TypeScript), it looks like a bug that a constant condition is checked on every iteration.

If TypeScript is indeed correct that location.attrs can be missing, then we already have an if-branch where that could be checked: L282. What do you think of using that?

@wooorm
Copy link
Member

wooorm commented Mar 30, 2022

Ping!

1 similar comment
@wooorm
Copy link
Member

wooorm commented May 27, 2022

Ping!

@wooorm wooorm closed this in f45d2ac May 27, 2022
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label May 27, 2022
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

2 participants