Skip to content

Commit 8fba2e9

Browse files
fuziontechclaude
andcommitted
fix(examples): correct import name and add DOM types
This commit fixes the generated example to work correctly: 1. **Import Fix**: - Changed from `import { posthog }` to `import hogtyped` (default import) - Updated all references from `posthog.capture` to `hogtyped.capture` - Matches the actual exports from generated code 2. **TypeScript Configuration**: - Added "DOM" to lib array in tsconfig.json - Fixes "Cannot find name 'window'" error in generated code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5d3fb89 commit 8fba2e9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

examples/generated/src/app.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77

88
// This file is auto-generated by running: npx hogtyped generate
9-
import { posthog } from './posthog.generated';
9+
import hogtyped from './posthog.generated';
1010

1111
// Initialize with your API key
12-
posthog.init('YOUR_API_KEY');
12+
hogtyped.init('YOUR_API_KEY');
1313

1414
// ============ Full Type Safety ============
1515

1616
// ✅ GOOD: All properties are type-checked at compile time
17-
posthog.capture('button_clicked', {
17+
hogtyped.capture('button_clicked', {
1818
buttonId: 'submit-btn',
1919
page: '/checkout',
2020
buttonText: 'Complete Purchase',
@@ -23,22 +23,22 @@ posthog.capture('button_clicked', {
2323

2424
// ❌ COMPILE ERROR: Missing required property 'page'
2525
// @ts-expect-error - This will not compile!
26-
posthog.capture('button_clicked', {
26+
hogtyped.capture('button_clicked', {
2727
buttonId: 'submit-btn'
2828
// Missing required 'page' property
2929
});
3030

3131
// ❌ COMPILE ERROR: Wrong property type
3232
// @ts-expect-error - This will not compile!
33-
posthog.capture('button_clicked', {
33+
hogtyped.capture('button_clicked', {
3434
buttonId: 'submit-btn',
3535
page: '/checkout',
3636
timestamp: 'not-a-number' // Should be number!
3737
});
3838

3939
// ============ Complex Events ============
4040

41-
posthog.capture('form_submitted', {
41+
hogtyped.capture('form_submitted', {
4242
formId: 'signup-form',
4343
formName: 'User Registration',
4444
fields: [
@@ -57,7 +57,7 @@ posthog.capture('form_submitted', {
5757
// 3. Provide inline documentation
5858
// 4. Catch typos before you even save the file!
5959

60-
posthog.capture('page_viewed', {
60+
hogtyped.capture('page_viewed', {
6161
url: 'https://example.com/products',
6262
title: 'Products | Example Store',
6363
referrer: 'https://google.com',
@@ -73,7 +73,7 @@ const untrustedData = JSON.parse('{"buttonId": "btn", "page": 123}'); // page sh
7373

7474
try {
7575
// This will pass TypeScript (any type) but fail at runtime
76-
posthog.capture('button_clicked', untrustedData as any);
76+
hogtyped.capture('button_clicked', untrustedData as any);
7777
} catch (error) {
7878
console.error('Runtime validation failed:', error);
7979
}

examples/generated/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2020",
44
"module": "commonjs",
5-
"lib": ["ES2020"],
5+
"lib": ["ES2020", "DOM"],
66
"outDir": "./dist",
77
"rootDir": "./src",
88
"strict": true,

0 commit comments

Comments
 (0)