0

I am building a Typescript library with JSX for learning purposes, and it is time to compile it to JavaScript. The problem is that I have a ./src/types/global.d.ts file in which there are global types, but it is not compiled/added into the build folder. Here is my configuration files:

package.json

{
  "name": "@riadh-adrani/ruvy",
  "version": "0.0.1",
  "type": "module",
  "types": "./build/index.d.ts",
  "exports": "./build/index.js",
  "license": "MIT",
  "engines": {
    "node": ">=16.0.0"
  },
  "files": [
    "build/**/*"
  ],
  "scripts": {
    "dev": "vite --config vite.dev.config.ts",
    "build": "rm -rf build && tsc -p tsconfig.build.json",
    "test": "vitest",
    "test:once": "vitest run",
    "lint:check": "npx eslint . --ext .ts",
    "format:check": "npx prettier --check ./",
    "lint": "npx eslint . --fix --ext .ts",
    "format": "npx prettier --write --check ./"
  },
  "devDependencies": {
    ...
  },
  "dependencies": {
    ...
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2016",
    "useDefineForClassFields": true,
    "module": "ES2020",
    "lib": ["ESNext", "DOM"],
    "moduleResolution": "node16",
    "rootDir": "./src",
    "outDir": "build",
    "strict": true,
    "declaration": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "jsxFactory": "createJsxElement",
    "jsxFragmentFactory": "createJsxFragmentElement",
    "jsx": "react",
    "typeRoots": ["./node_modules/@types", "./src/types"]
  },
  "include": ["src", "src/types/global.d.ts"]
}

tsconfig.build.json

{
  "extends": "./tsconfig",
  "exclude": ["**/*.test.ts", "**/*.test.tsx", "./src/dev"]
}

global.d.ts structure

declare global {
// too many types and interfaces

  namespace JSX {
    // too many types and interfaces
  }
}

Any suggestion/help is welcomed. Thanks.

Riadh Adrani
  • 486
  • 2
  • 5
  • 16

1 Answers1

0

According to this answer :

Basically .d.ts files are seen as untouchable input for the compiler to do type checks. They are not used for any output generation, which also means, they do not get copied over to build.

Riadh Adrani
  • 486
  • 2
  • 5
  • 16