TypeScript codegen omits an argument-only core type from the generated import list (Secret → TS2304)
What is the issue?
The TypeScript client generator emits a generated module client that references a core type in a method signature but does not add that type to the file's import list. The type is exported from a sibling generated file, so the code is one import line away from compiling. tsc fails on the generated output.
The trigger is specific: a core type is omitted from the import list when it is used only as a function argument and never as a return type. A type that also appears in a return position is imported correctly.
Both generated copies are affected — the module SDK (sdk/<module>.gen.ts) and the bundled client (clients/<module>.gen.ts).
Reproduction (clean room, verified)
mkdir repro && cd repro && git init -q && git commit -q --allow-empty -m init
dagger init
dagger install dagger.io/sdk/typescript
dagger module init typescript --name repro -yReplace .dagger/modules/repro/src/index.ts with a single function that takes a Secret argument and returns something other than a Secret:
import { func, object, Secret } from "@dagger.io/dagger"
@object()
export class Repro {
// `Secret` is used ONLY as an argument here.
// Nothing in this module returns a `Secret`.
@func()
async useSecret(token: Secret): Promise<string> {
return token.plaintext()
}
}Then:
dagger generate -yActual behavior
The generated client references Secret in the useSecret signature but never imports it:
// .dagger/modules/repro/sdk/repro.gen.ts — auto-generated by client-gen
import { Context, BaseClient } from "./core.js"
import type {
ID
} from "./client.gen.js"
// no import of `Secret`
useSecret = async (token: Secret): Promise<string> => { … }
// ^^^^^^ TS2304: Cannot find name 'Secret'tsc --noEmit reports:
clients/repro.gen.ts(48,29): error TS2304: Cannot find name 'Secret'.
sdk/repro.gen.ts(48,29): error TS2304: Cannot find name 'Secret'.Secret is exported from the sibling generated file (sdk/client.gen.ts: export class Secret extends BaseClient), so it is in scope to import. The failure is silent at runtime, because the type is erased during transpile — it only surfaces on a type check.
The discriminator (argument vs return)
Adding a second function that returns a Secret makes the generator value-import it, and the error disappears:
import { dag, func, object, Secret } from "@dagger.io/dagger"
@object()
export class Repro {
@func()
async useSecret(token: Secret): Promise<string> {
return token.plaintext()
}
// `Secret` now also appears as a RETURN type.
@func()
wrap(value: string): Secret {
return dag.setSecret("s", value)
}
}After dagger generate -y, the generated imports become:
import { Context, BaseClient } from "./core.js"
import {
Secret
} from "./client.gen.js"
import type {
ID
} from "./client.gen.js"So the import collection appears to gather types from return positions but miss types that appear only as arguments.
Expected behavior
A core type referenced in any signature position — argument or return — is included in the generated file's imports, so the generated client type-checks.
Version
dagger version:v1.0.0-beta.14(commit06660c3c).- TypeScript SDK installed from
dagger.io/sdk/typescript(github.com/dagger/typescript-sdk#v1). - Also reproduces on
main: the TypeScript codegen appears unchanged since before thebeta.14tag, so no released version fixes it.
Possibly related
The import collection in cmd/codegen/generator/typescript/templates/functions.go (collectReferencedNames / coreValueNames) looks like the relevant path; there appears to be a gap for the argument-only case. (Not verified — worth a maintainer's eye.)
Workaround
Post-process the generated *.gen.ts after dagger generate to add the missing argument-only type to the import from ./client.gen.js. This patches around the generator; it is not a fix.
Source: dagger/dagger