davidtheclark / davidtheclark/react-aria-modal

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

Open
#84 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
94
PR merge metrics
No merged PRs in 30d

Description

# The Problem

When using react-aria-modal in combination with [TypeScript compiler option](https://www.typescriptlang.org/docs/handbook/compiler-options.html) `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](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById#Return_value), 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`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.