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

Rest operator used in object destructuring is not correctly type-checked

Open fingerartur opened this issue 3 years ago • 1 comments

/**
 * @type {{ x: number, y: number, w: number, h: number }}
 */
const rect = { x: 0, y: 0, w: 100, h: 100 };

/**
 * @typedef {{ x: number, y: number }}
 */
var Point;

const { w, h, ...point } = rect
/**
 * @type {Point}
 */
const point2 = point

This produces the following error:

./src/js/index.js:22:15: WARNING - [JSC_TYPE_MISMATCH] initializing variable
found   : Object
required: {
  x: number,
  y: number
}
missing : [x,y]
mismatch: []
  22| const point2 = point
                     ^^^^^

In essence, point variable is interpreted as Object type even though it clearly should have { x: number, y: number} type.

Vaguely related to #3132

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 11 '23 16:01 fingerartur

This is not something that we are currently prioritizing.

blickly avatar Jan 18 '23 17:01 blickly