closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Union types need brackets

Open fingerartur opened this issue 1 year ago • 8 comments

Even simple union types require brackets (e.g. (number|undefined)) without brackets there is a warning.

/**
* @type {{
*  age: number|undefined, // WARNING - [JSC_TYPE_PARSE_ERROR] Bad type annotation.
* }}
*/
const person = {}

It would be nice to have support for the good old simple bracketless syntaxnumber|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;

fingerartur avatar Jan 09 '23 21:01 fingerartur