Skip to content

My app produces invalid type definitions after v1.17.1 #705

@adamstoffel

Description

@adamstoffel

Description of the Issue

Typescript definition files for an application which uses this library are generated with invalid import references with files ending in .js.js. Eg:

// some-file.d.ts
...
export declare function someFunction(): {
    pathCollection: {
        entries: import("box-typescript-sdk-gen/lib/schemas/folderMini.generated.js.js").FolderMini[];
    };
};
...

This seems to specifically happen when tsconfig moduleResolution is set to bundler. Which is necessary for our use case.

Steps to Reproduce

The files below comprise a very simple example of an app with this issue:

package.json:

{
  "name": "box_typing_issue",
  "version": "1.0.0",
  "scripts": {
    "prebuild": "npm install",
    "build": "tsc -p tsconfig.json"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "box-typescript-sdk-gen": "^1.17.1"
  },
  "devDependencies": {
    "typescript": "^5.4.4"
  }
}

tsconfig.json:

{
    "compilerOptions": {
      "outDir": "./dist",
      "moduleResolution": "bundler",
      "importHelpers": true,
      "target": "ES2022",
      "module": "es2020",
      "lib": [
        "es2020",
        "dom"
      ],
      "strict": true,
      "esModuleInterop": true,
      "declaration": true,
      "declarationMap": true,
      "inlineSources": true,
      "sourceMap": true,
      "skipLibCheck": true,
      "types": []
    },
    "include": [
      "src/**/*.ts" 
    ]
  }

src/index.ts:

import { FolderFull } from "box-typescript-sdk-gen/lib/schemas/folderFull.generated";
// Note, same issue if you use (without /lib/):
// import { FolderFull } from "box-typescript-sdk-gen/schemas/folderFull.generated";

export type SnakeToCamel<S extends string> = S extends `${infer T}_${infer U}`
  ? `${T}${Capitalize<SnakeToCamel<U>>}`
  : S;

const PARENT_FIELDS = [
  "id",
] as const;

export interface ParentFolder
  extends Pick<FolderFull, SnakeToCamel<(typeof PARENT_FIELDS)[number]>> {
  id: NonNullable<FolderFull["id"]>;
  name: NonNullable<FolderFull["name"]>;
  type: NonNullable<FolderFull["type"]>;
  pathCollection: NonNullable<FolderFull["pathCollection"]>;
}

export function systemFileToMinimalItem(
  file: File,
  parentFolder: ParentFolder
) {
  return {
    name: file.name,
    type: "file",
    size: file.size,
    pathCollection: {
      entries: parentFolder.pathCollection.entries.concat(parentFolder),
    },
  };
}

Run npm run build and look at dist/index.d.ts

Expected Behavior

Types should be generated correctly with no extension.

Error Message, Including Stack Trace

n/a

Screenshots

Image

Versions Used

Typescript SDK: 5.4.4
Platform: Browser
Node.js (if applicable): n/a

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions