Skip to content

Behavior difference: tsgo & tsc throw differently when spreading variable with type {} #4214

@hkleungai

Description

@hkleungai

Previous discussion on similar issue: #3739 (comment).


Steps to reproduce

  1. Start a plain new project
    • "@typescript/native-preview": "7.0.0-dev.20260605.1",
    • "typescript": "6.0.3"
  2. Run npx tsgo --init to get the default tsconfig. Turn on these flags as well.
    • "allowJs": true,
    • "checkJs": true,
    • "stableTypeOrdering": true,
  3. Add src/main.js. Run npx tsc --noEmit & npx tsgo --noEmit to see the difference.
/** @type {unknown} */
let foo;
const { bar = {} } = foo ?? {};
const { buzz = {} } = {};

Behavior with typescript@6.0

src/main.js:4:9 - error TS2339: Property 'buzz' does not exist on type '{}'.

4 const { buzz = {} } = {};
          ~~~~


Found 1 error in src/main.js:4

Behavior with tsgo

src/main.js:3:9 - error TS2339: Property 'bar' does not exist on type '{}'.

3 const { bar = {} } = foo ?? {};
          ~~~


Found 1 error in src/main.js:3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions