Skip to content

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

@jfirebaugh

Description

@jfirebaugh

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 typescript@5.9

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions