Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/locals-key-dual-package-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

Fix `LocalsKey<T>` type incompatibility across dual-package builds. The phantom value-type brand no longer uses a module-level `unique symbol`, so a single TypeScript compilation that resolves the type from both the ESM and CJS outputs (which can happen under certain pnpm hoisting layouts) no longer sees two structurally-incompatible variants of the same type.
4 changes: 2 additions & 2 deletions packages/core/src/v3/locals/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class NoopLocalsManager implements LocalsManager {
return {
__type: Symbol(),
id,
} as unknown as LocalsKey<T>;
};
}

getLocal<T>(key: LocalsKey<T>): T | undefined {
Expand All @@ -23,7 +23,7 @@ export class StandardLocalsManager implements LocalsManager {
return {
__type: key,
id,
} as unknown as LocalsKey<T>;
};
}

getLocal<T>(key: LocalsKey<T>): T | undefined {
Expand Down
24 changes: 18 additions & 6 deletions packages/core/src/v3/locals/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
declare const __local: unique symbol;
type BrandLocal<T> = { [__local]: T };

// Create a type-safe store for your locals
export type LocalsKey<T> = BrandLocal<T> & {
/**
* A type-safe key for `locals`. Carries the value type `T` as a phantom
* marker on the optional `__valueType` field so two keys with different
* value types are distinguishable at the type level.
*
* The phantom field is intentionally not anchored to a `unique symbol`:
* dual-package builds (`tshy`) emit separate `.d.ts` files for ESM and
* CJS outputs, and each `unique symbol` declaration in a `.d.ts` is its
* own nominal type. If a single compilation ever resolves `LocalsKey`
* from both the ESM and CJS paths — which happens under certain pnpm
* hoisting layouts — `unique symbol` brands produce structurally
* incompatible variants of the same type. A plain string brand avoids
* the hazard.
*/
export type LocalsKey<T> = {
readonly id: string;
readonly __type: unique symbol;
readonly __type: symbol;
/** Phantom carrier for the value type — never read at runtime. */
readonly __valueType?: T;
};

export interface LocalsManager {
Expand Down
Loading