-
Notifications
You must be signed in to change notification settings - Fork 12.8k
'innerText' should not be nullable in most of Node's derived types #10315
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
Comments
PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes. |
Unfortunately https://dom.spec.whatwg.org/#dom-node-textcontent I have tried to use getter and setter to fix this, but that seems not possible because "'get' and 'set' accessor must have the same type". get textContent(): string;
set textContent(value: string | null); |
Another test case: const span : HTMElement | null = document.body.querySelector('span');
let value: string = '';
if (span instanceof HTMLElement) {
value = span.textContent; // Type 'string | null' is not assignable to type 'string'.
} Expected:Valid, since anything subclass of |
@FranklinWhale That depends on #32821/#2521. |
Can't TypeScript just be a little stricter than the spec here, and disallow setting |
It doesn't even need to, as far as I can tell the needed behaviour here has worked since TS4.3. |
This would be quite a nice improvement. The DOM types are heavily generated and it's not straightforward to tinker with them. Perhaps @saschanaz could advise how this could be achieved in practice there? I could give it a shot then. |
Compile the following with
--strictNullChecks
with the DOM available.Expected: No error
Actual:
Type 'string | null' is not assignable to type 'string'.
From https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent:
Proposed fix:
textContent will be defined as nullable in
Node, but overridden as
string` in most of its descendants.The text was updated successfully, but these errors were encountered: