1

In the TypeScript documentation on .d.ts declaration files, all the function signatures and interfaces and such seem to be exported. However I'm familiar with the idea of ambient declarations in files with no imports or exports, and have been doing basically what is described in this StackOverflow answer for projects. In my case though I haven't been using .d.ts, just .ts and it seems to be working how I intend. I just have a .ts file in the root of my project with a bunch of interfaces and types that just look like this

interface BuildContext {
    selectedBuild: import('./classes/build').Build
    setSelectedBuild: (buildId: number) => void
    modifySelectedBuild: (build: import('./classes/build').Build) => void
}

type StatData = {
    statId: number,
    statName: string,
    alias: string | null
}

Doing imports that way was explained in the answer I linked above as a way to keep the declarations ambient while still accessing definitions in other files. Other than those inline imports, there are no imports or exports, and I don't seem to have any problems. Is the .d part of .d.ts simply a naming convention, or does it have some purpose I'm not understanding?

My tsconfig.json if it makes a difference:

{
  "compilerOptions": {
    "outDir": "./dist/",
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "resolveJsonModule": true
  }
}

0 Answers0