• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
yawnxyz

yawnxyz

chatter

Public
Like
chatter
Home
Code
18
backend
4
frontend
24
scripts
2
.gitignore
.vtignore
BRANCH_DATA_MODEL.md
HOTFIX.md
REFACTORING_SUMMARY.md
TYPESCRIPT_FIXES.md
TYPESCRIPT_MIGRATION.md
chatCompletion.js
chatStreaming.js
deno.json
deno.lock
index.html
H
main.js
notes.md
readme.md
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
TYPESCRIPT_FIXES.md
Code
/
TYPESCRIPT_FIXES.md
Search
10/8/2025
TYPESCRIPT_FIXES.md

TypeScript Migration Fixes

Issues Encountered and Fixed

1. Import Typo

Error: timerStopf instead of timerStop File: frontend/chatterApp.js line 86 Fix: Changed stopTimer as timerStopf to stopTimer as timerStop

2. Missing Function References

Error: coreEnsureMessagePersisted and coreSendMessage not exported Fix:

  • Replaced coreEnsureMessagePersisted with corePersistMessageAtIndex
  • Inlined the legacy coreSendMessage implementation directly in sendMessage()

3. TypeScript Type Exports in Browser

Error: Browser can't parse export type { ... } File: frontend/core/index.ts Fix: Removed export type { AppState, DexieDatabase } line

4. TypeScript MIME Type Issue

Error: Server serving .ts files as text/plain instead of application/javascript File: backend/routes/static.js Fix: Added TypeScript transpilation using Deno's emit module

if (rel.endsWith('.ts')) { const { transpile } = await import('https://deno.land/x/emit@0.31.0/mod.ts'); const result = await transpile(new URL(`file://${Deno.cwd()}/${rel}`)); body = result.get(new URL(`file://${Deno.cwd()}/${rel}`).href) || body; contentType = 'application/javascript; charset=utf-8'; }

5. Duplicate Function Declarations

Error: Functions declared twice in types.ts Fix: Removed duplicate declarations:

  • messageToUIMessage (was on lines 333 and 395)
  • createDefaultSessionTree (was on lines 263 and 395)

Why TypeScript Doesn't Work in Browsers

Browsers only understand JavaScript, not TypeScript. TypeScript features like:

  • import type { ... } - Type-only imports
  • interface declarations
  • type aliases
  • Type annotations (: string, : number, etc.)
  • export type

All of these cause syntax errors in browsers.

Solution: Server-Side Transpilation

The server now transpiles TypeScript to JavaScript on-the-fly:

  1. Browser requests .ts file
  2. Server reads the TypeScript source
  3. Server uses Deno's emit module to transpile it
  4. Server serves the transpiled JavaScript (with all TypeScript syntax removed)
  5. Browser runs pure JavaScript

Files Modified

  1. backend/routes/static.js - Added TypeScript transpilation
  2. frontend/chatterApp.js - Fixed import typos and missing functions
  3. frontend/core/index.ts - Removed export type
  4. frontend/types.ts - Removed duplicate function declarations

Testing Checklist

  • App loads without errors
  • Create new chat works
  • Send message works
  • Reasoning displays
  • Branch switching works
  • Fork functionality works
  • Refresh preserves data

Performance Note

TypeScript transpilation happens on every request. For production, consider:

  1. Pre-compiling TypeScript to JavaScript
  2. Caching transpiled results
  3. Using a build step to generate .js files

For development, the current on-the-fly transpilation works fine.

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.