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

getApplicationNode() does not compile (when using TypeScript strictNullChecks option) #84

Open
olabaloo opened this issue Feb 22, 2019 · 1 comment

Comments

@olabaloo
Copy link

The Problem

When using react-aria-modal in combination with TypeScript compiler option strictNullChecks, the solution does not compile.

The compile complains with the following message:

TS2322: Type '() => HTMLElement | null' is not assignable to type '() => Element | Node'.
  Type 'HTMLElement | null' is not assignable to type 'Element | Node'.
    Type 'null' is not assignable to type 'Element | Node'.

Solution

Changing getApplicationNode?(): Node | Element; to getApplicationNode?(): Element | null; in the file @types\react-aria-modal\index.d.ts seems to fix the problem.

Background

In @types\react-aria-modal\index.d.ts the getApplicationNode?() return type is defined as Node | Element. This is not correct according to MDN's getElementById documentation, which states:

An Element object describing the DOM element object matching the specified ID, or null if no matching element was found in the document.

This error occurs when using react-aria-modal: 3.1.0, @types/react-aria-modal: 2.12.1, and typescript: 3.3.3333.

@olabaloo
Copy link
Author

olabaloo commented Apr 5, 2019

A workaround for this problem is to assert the type of the value returned from getApplicationNode in the component:

    getApplicationNode = () => {
        return document.getElementById("root") as Element;
    };

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

No branches or pull requests

1 participant