Skip to content

Commit 8539d37

Browse files
committed
fix(webapp): declare @growthbook type shim for bundler resolution
Under `moduleResolution: "bundler"` (introduced for webapp in #5952), TS respects each package's `exports` map. The growthbook packages only expose `require`/`import` conditions, so the .d.ts files in `dist/` are no longer reachable and the strict typecheck flags every file that imports types from them. Declare the small subset (JSONValue, WidenPrimitives, FeatureDefinition, GrowthBook, hooks) that the codebase actually consumes in the webapp's custom.d.ts.
1 parent 1456b4e commit 8539d37

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

packages/webapp/custom.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,53 @@ declare module '*.svg' {
44
const value: SvgrComponent;
55
export default value;
66
}
7+
8+
// `@growthbook/growthbook(-react)` ship .d.ts files in their `dist/` folders,
9+
// but their package.json `exports` map only lists "require"/"import" — under
10+
// `moduleResolution: "bundler"` TypeScript respects `exports` and can no
11+
// longer reach the typings. Declare the subset we actually consume so type
12+
// imports keep resolving without falling back to `any`.
13+
declare module '@growthbook/growthbook' {
14+
export type JSONValue =
15+
| null
16+
| number
17+
| string
18+
| boolean
19+
| Array<JSONValue>
20+
| { [key: string]: JSONValue };
21+
export type WidenPrimitives<T> = T extends string
22+
? string
23+
: T extends number
24+
? number
25+
: T extends boolean
26+
? boolean
27+
: T;
28+
export interface FeatureDefinition<T = unknown> {
29+
defaultValue?: T;
30+
rules?: unknown[];
31+
}
32+
export type Experiment = Record<string, unknown>;
33+
export type Result = Record<string, unknown>;
34+
export interface GrowthBook {
35+
[key: string]: unknown;
36+
}
37+
export const GrowthBook: {
38+
new (options?: unknown): GrowthBook;
39+
};
40+
}
41+
42+
declare module '@growthbook/growthbook-react' {
43+
export interface GrowthBook {
44+
[key: string]: unknown;
45+
}
46+
export const GrowthBook: {
47+
new (options?: unknown): GrowthBook;
48+
};
49+
export const GrowthBookProvider: React.FC<{
50+
children?: React.ReactNode;
51+
growthbook?: GrowthBook;
52+
}>;
53+
export function useFeatureValue<T>(key: string, fallback: T): T;
54+
export function useGrowthBook(): GrowthBook | undefined;
55+
export function useFeatureIsOn(key: string): boolean;
56+
}

0 commit comments

Comments
 (0)