typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

TS2742: The inferred type of 'default' cannot be named

Open jfirebaugh opened this issue 2 weeks ago • 0 comments

Still getting these types of errors even after the fixes for #1034.

Steps to reproduce

package.json:

{
  "type": "module",
  "dependencies": {
    "@stylexjs/stylex": "0.16.2"
  }
}

tsconfig.json:

{
    "compilerOptions": {
        "module": "node20",
        "moduleResolution": "node16",
        "skipLibCheck": true,
        "declaration": true,
    }
}

stylex.ts:

import * as stylex from '@stylexjs/stylex'

export default { ...stylex } as { [K in keyof typeof stylex]: (typeof stylex)[K] }

Behavior with [email protected]

No error.

Behavior with tsgo

stylex.ts:3:1 - error TS2742: The inferred type of 'default' cannot be named without a reference to './node_modules/@stylexjs/stylex/lib/es/types/StyleXCSSTypes.js'. This is likely not portable. A type annotation is necessary.

3 export default { ...stylex } as { [K in keyof typeof stylex]: (typeof stylex)[K] }
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

stylex.ts:3:1 - error TS2742: The inferred type of 'default' cannot be named without a reference to './node_modules/@stylexjs/stylex/lib/es/types/StyleXUtils.js'. This is likely not portable. A type annotation is necessary.

3 export default { ...stylex } as { [K in keyof typeof stylex]: (typeof stylex)[K] }
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: stylex.ts:3

There's a straightforward workaround for me -- simplify { [K in keyof typeof stylex]: (typeof stylex)[K] } to typeof stylex. Reporting in case this is a variant of #1034 you want to fix.

This one doesn't appear to be related to pnpm. It repros with npm i.

jfirebaugh avatar Dec 08 '25 19:12 jfirebaugh