Skip to content

The inferred type of 'renderWithTheme' cannot be named without a reference to @types/testing-library__dom/queries'. This is likely not portable. A type annotation is necessary. #587

@RIP21

Description

@RIP21
  • @testing-library/react version: 9.4.0
  • react version: 16.12.0
  • node version: 12.14.1
  • pnpm version: 4.9.3
  • yarn version: 1.21.1

Relevant code or config:

import { render } from '@testing-library/react'
import { withTheme } from './withTheme'

export const renderWithTheme = (component: React.ReactElement) =>
  render(withTheme(component)) // No matter withTheme or just render, same error

What you did:

What happened:

Reproduction:

  1. Install Typescript
  2. Install @testing-library/react
  3. Add any function that takes component and returns render(component)
  4. Run tsc with following config
{
  "compilerOptions": {
    "baseUrl": "src",
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "declarationDir": "./types",
    "declarationMap": true,
    "downlevelIteration": true,
    "emitDeclarationOnly": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "lib": ["dom", "es2018"],
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext"
  },
  "include": ["src"],
  "exclude": [
    "./src/**/__tests__/**/*.ts",
    "./src/**/__tests__/**/*.tsx",
    "./src/**/*.test.tsx",
    "./src/**/*.test.ts"
  ]
}

Problem description:

I tried yarn as well as the pnpm, the result is the same all the time.
Cannot compile declarations with this error:

The inferred type of 'renderWithTheme' cannot be named without a reference to '../../../../common/temp/node_modules/.pnpm/registry.npmjs.org/@types/testing-library__react/9.1.2/node_modules/@types/testing-library__dom/queries'. This is likely not portable. A type annotation is necessary.

Suggested solution:

I have no idea.

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