Skip to content

TypeScript types reference internal modules (causing TS 2742) in downstream packages #105

@kevbook

Description

@kevbook

When using the assemblyai package inside another TypeScript package and exporting a function that returns or includes types from AssemblyAI, TypeScript produces the following error during declaration emit:

error TS2742: The inferred type of 'transcribeAudio' cannot be named without a reference to 'assemblyai/dist/types/helpers'

This happens because the .d.ts files reference internal type modules (e.g. dist/types/helpers.d.ts) which are not exposed through the package’s exports map.

As a result, any library that depends on assemblyai cannot safely re-export or use AssemblyAI’s types in its public API.

Steps to Reproduce

import { AssemblyAI } from "assemblyai";

export async function transcribeAudio(apiKey: string) {
  const client = new AssemblyAI({ apiKey });
  return client.transcripts.transcribe({ audio: "https://example.com/file.mp3" });
}

Suggested Fix

In package.json, the exports["."] types field should point to a .d.ts file that re-exports all relevant public types

// Example: dist/exports/index.d.ts
export * from "../types/helpers";
export * from "../types/client";
export * from "../types/transcripts";

Se we can add a type-flattening step using rollup-plugin-dts at the end of the Rollup build:

const dts = require("rollup-plugin-dts").default;

{
  input: "src/exports/index.ts",
  plugins: [dts()],
  output: {
    file: "./dist/exports/index.d.ts",
    format: "es",
  },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions