google / google/closure-compiler
Object type with generic parameters does not get type checked as it should
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
As described [here in the doc](https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System) it should be possible to check the type of values or keys and values of an Object via generics.
**However the type check does not work.**
```js
/**
* @type {Object}
*/
const x = {
hello: 555, // This should raise error, but does not
}
```
```js
/**
* @type {Object}
*/
const x = {
hello: 1,
name: "John" // This should raise error, but does not
}
```
Possibly related to #1937
Compiler Version: v20221102
Build command:
```bash
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;
```
Adding `--jscomp_error=strictCheckTypes` option does not help.
Contributor guide
Assessment
This issue has not been assessed yet.