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

chore: makes types of divs more specific #5988

Merged
merged 3 commits into from
Mar 9, 2022

Conversation

rachel-fenichel
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

Part of #5857

Proposed Changes

  • Add casts when calling document.createElement('div').
  • Update types for properties, return types, and parameters that can be more specific as a result.

Behavior Before Change

These were annotated as Element. The typescript compiler threw errors, saying that style and similar properties do not exist on Element.

Behavior After Change

Code works the same but tsc has fewer errors.

Reason for Changes

Improve typing/fix errors.
tsc doesn't actually care about the casts when the divs are created and used immediately, because it's clever. But tsc cares about having the correct types when the divs are saved or passed around, and the closure compiler needs the casts to agree that it's safe.

Test Coverage

Documentation

Additional Information

Comment on lines +62 to +63
const subContainer =
/** @type {!HTMLDivElement} */ (document.createElement('div'));
Copy link
Contributor

Choose a reason for hiding this comment

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

If only it would work to type the variable rather than the initialiser:

  const /** !HTMLDivElement */ subContainer = document.createElement('div');

Alas…

@rachel-fenichel rachel-fenichel merged commit 3740d51 into google:develop Mar 9, 2022
@rachel-fenichel rachel-fenichel deleted the small_fixes branch March 9, 2022 00:00
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.

3 participants