Skip to content

Unnecessary 'use client' directive in Typescript declaration files #1257

@Morabotti

Description

@Morabotti

Description

Typescript definition files generated by nuqs include 'use client' directive, which cause typescript type error when running tsc. I don't see reason why this directive should be in the *.d.ts files. The problem can be fixed with "skipLibCheck": true option, but I would rather keep it as false.

Context

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "tsc"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "description": "",
  "dependencies": {
    "nuqs": "^2.8.3",
    "react": "^19.2.1",
    "typescript": "^5.9.3"
  },
  "devDependencies": {
    "@types/react": "^19.2.7"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "types": [],
    "jsx": "react",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "resolveJsonModule": true,
    "noEmit": true,
    "declaration": true,
    "declarationMap": true,
    "verbatimModuleSyntax": true,
    "isolatedDeclarations": true,
    "moduleDetection": "force",
    "downlevelIteration": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": false
  },
  "include": ["src/*.ts"],
  "exclude": ["node_modules"]
}

src/index.ts

import { useQueryState } from 'nuqs';
import { renderQueryString } from 'nuqs/adapters/custom';

Reproduction

  1. Copy the minimal setup provided in context
  2. Run npm run test
  3. See error

Gotten error:

$ tsc
node_modules/nuqs/dist/adapters/custom.d.ts:1:1 - error TS1036: Statements are not allowed in ambient contexts.

1 'use client';
  ~~~~~~~~~~~~

node_modules/nuqs/dist/index.d.ts:1:1 - error TS1036: Statements are not allowed in ambient contexts.

1 'use client';
  ~~~~~~~~~~~~


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/nuqs/dist/adapters/custom.d.ts:1
     1  node_modules/nuqs/dist/index.d.ts:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions