Closed
Description
TypeScript Version: 2.1.5 (bug is present on master)
Code
const element = document.createElement('div');
const dataset = element.dataset;
dataset['key1'] = 'Hello';
console.log(dataset['key1'].toUpperCase()); // HELLO
console.log(dataset['key2'].toUpperCase()); // Cannot read property 'toUpperCase' of undefined
Expected behavior:
The project doesn't compile with a type error.
Actual behavior:
The project does compile, and a runtime error occurs.
This is caused by the fact that DOMStringMap
's index return has type string
, and not string | undefined
.
We want
interface DOMStringMap {
[name: string]: string;
}
To be
interface DOMStringMap {
[name: string]: string | undefined;
}
If this is approved, I am very happy to make a PR on this - and would like to do so to try and contribute to TypeScript codebase.