google / google/closure-compiler
`Map.get` return type should be `T|undefined`
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
The `get` method of `Map` returns `undefined` when you look for a key that is not in the map, but the types do not reflect that.
```js
/**
* @type {Map}
*/
const map = new Map()
map.set('john', 1)
/**
* @type {number}
*/
const value = map.get('jack') // should produce error, value is obviously undefined, but types say that it is a number
```
The return type of `Map.get` should be `T|undefined`.
Compiler Version: v20221102
Build command:
```
java -jar ./scripts/closureCompiler.jar \
--entry_point=./src/js/index.js \
--js=./src/**.js \
--dependency_mode=PRUNE \
--warning_level=VERBOSE \
--js_output_file=./dist/bundle.js \
--module_resolution=WEBPACK \
--compilation_level=ADVANCED \
--jscomp_error=checkDebuggerStatement \
--jscomp_error=unusedLocalVariables \
--jscomp_error=reportUnknownTypes \
--jscomp_error=strictCheckTypes;
```
Contributor guide
Assessment
This issue has not been assessed yet.