HaxeFoundation / HaxeFoundation/haxe
js.html.Storage.getItem should take into account possible null values
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
## Description
The return type of the method `js.html.Storage.getItem()` is `String` in the [Haxe API documentation](https://api.haxe.org/js/html/Storage.html#getItem), but the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem) state that it can also return `null`.
## Steps to reproduce the issue
Run [this snippet](https://try.haxe.org/#a1CbD24a) to see that the `Storage.getItem()` method can return `null`, so that the `@:nullSafety` macro can warn against null accesses.
```haxe
import js.Browser;
class Test {
static function main() {
final toggleDarkMode = Browser.window.localStorage.getItem("toggle-dark-mode");
trace(toggleDarkMode == null);
}
}
```
```
16:25:48:960 Test.hx:7:,true
```
## Expected behavior
The signature of `js.html.Storage.getItem()` is taking into account null values:
```haxe
getItem(key:String):Null
```
Contributor guide
Assessment
This issue has not been assessed yet.