Skip to content

Google feedback on TypeScript 4.4-beta #45047

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

Closed
h-joo opened this issue Jul 15, 2021 · 5 comments
Closed

Google feedback on TypeScript 4.4-beta #45047

h-joo opened this issue Jul 15, 2021 · 5 comments
Labels
Discussion Issues which may not have code impact

Comments

@h-joo
Copy link
Contributor

h-joo commented Jul 15, 2021

Feedback to the TypeScript team for TypeScript 4.4-beta

This GitHub issue contains feedback on the TS 4.4-beta release from the team
that is responsible for keeping Google's internal software working with the
latest version of TypeScript.

During the 4.4-beta migration, we have ran into some issues. Especially some
changes made in lib.dom.d.ts will make it diffilcut for Google to migrate. We've
listed the breaking changes which we weren't able to easily migrate in the
following section.

Breakages which are complicated to migrate

Each subsection in this section contains a diagnosis of the breakage and a link
to the github issue if available.

canvas API changes in WebGL

WebGL2RenderingContext no longer seems to have a .canvas field, however the
WebGLRenderingContext does have one. TS now doesn't list one on either API.
There seems to be a github issue
related to the failure, and it seems it has been fixed already.

Readonly attributes in DOMPoint, DOMMatrix, DOMRect

Some properties of DOMPoint, DOMMatrix, DOMRect became readonly, and this no
longer match the specification. This is because these types no longer override
properties from the extended types to be read/write.

Compare(DOMPoint):

Compare(DOMMatrix):

Compare(DOMRect):

Removed Types

SpeechRecognition, RTCError got removed from lib.dom.d.ts. There are existing
code which use this API, and it would be difficult to migrate without proper
type support either from the compiler or from definitelyTyped.

Offscreen Rendering API changes

OffscreenCanvas still exists, but it's marked as deprecated. Though it is no
longer a value, i.e. code calling new OffscreenCanvas no longer works, it's
just an interface. We think this might be unintentional. Though, we would still
be able to migrate via referring to the types defined in
DefinitelyTyped.

ShadowRoot interface changes

ShadowRoot is a subtype of DocumentFragment. DocumentFragment has a
getElementById which returns HTMLElement. In 4.4-beta, DocumentFragment no
longer defines its own getElementById method, meaning
HTMLElement.prototype.shadowRoot.getElementById returns Element, not
HTMLElement. This causes hundreds of breakages of code using shadowRoot.

ChildNode interface changes

In 4.4, ChildNode no longer extends Node. This seems like a bug.

DocumentOrShadowRoot interface changes

DocumentOrShadowRoot no longer has getSelection, elementFromPoint,
elementsFromPoint, caretFromRange. We also couldn't find in the repo whether
this was intentional or not.

Impact summary (trivial fix unavailable)

Change description Libraries affected
type of ariaLabel is string rather than string/null 0.079%
ShadowRoot interface changes 0.034%
OffscreenCanvas Rendering API changes 0.014%
Removed Types 0.009%
Newly readonly attributes 0.008%
DocumentOrShadowRoot interface changes 0.005%
ChildNode interface changes 0.004%
canvas API changes 0.004%

Impact summary (trivial fix available)

Change description Libraries affected
window.parent nullability changes 0.088%
misc and other changes 0.088%
Various Media Related API changes 0.019%
window.location.reload interface changes 0.014%
Navigator API changes 0.012%
Promise always evaluate to true or false 0.011%
CustomElementConstructor interface changes 0.010%
Property has no initializer 0.008%
Infinite depth type inference 0.002%
property specified more than once in object literal 0.002%
document.createTreeWalker interface changes 0.001%
@DanielRosenwasser
Copy link
Member

@h-joo thank you very much for this summary! It sounds like Google didn't run into any issues with new strictness flags being introduced. Do you all run with --strict on, or with a manually-specified set of strictness flags?

@DanielRosenwasser DanielRosenwasser added the Discussion Issues which may not have code impact label Jul 15, 2021
@h-joo
Copy link
Contributor Author

h-joo commented Jul 16, 2021

Do you all run with --strict on, or with a manually-specified set of strictness flags?

We've been doing the latter. That'd be the reason that we had no issues with the strictness flags. We will discuss this internally whether we want to turn the new flags on. Thank you for mentioning this.

@goremikins
Copy link

Following the review from @h-joo , it looks wrong to remove getSelection, elementFromPoint and elementsFromPoint methods from DocumentOrShadowRoot. Consider the scenario when the developer needs to get an element inside ShadowDom from coordinates, the only way to get those is by calling ShadowRoot.elementFromPoint.

These methods are supported by major browsers and described in https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot.

@orta
Copy link
Contributor

orta commented Aug 27, 2021

getSelection shouldn't:

Screen Shot 2021-08-27 at 6 09 48 PM

but elementFromPoint and elementsFromPoint maybe should probably be there, feel free to open an issue/PR on the dom types lib 👍🏻

@RoXuS
Copy link

RoXuS commented Sep 3, 2021

we use getSelection from shadowRoot since long time and now we get this error:

image

(with lit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Issues which may not have code impact
Projects
None yet
Development

No branches or pull requests

6 participants