Import and Export

Import Export
πŸ‘¨β€πŸ’Ό Our code is getting large. Let's split it into separate modules to keep things organized.
// data.ts
export const book = { title: 'TypeScript Tips', pages: 200 }

// index.ts
import { book } from './data.ts'
🐨 Open
data.ts
and
index.ts
and:
  1. Move the user and product objects from index.ts into data.ts
  2. Export them from data.ts as named exports with these fixtures:
    • user: { id: '1', name: 'Alice', email: 'alice@example.com' }
    • product: { id: 'p1', name: 'Laptop', price: 999.99 }
  3. Import { user, product } back into index.ts
  4. Export displayUser and displayProduct from index.ts
Completion check: index.ts can call both display helpers with the imported values, and both helpers are exported from the module.

Please set the playground first

Loading "Import and Export"
Loading "Import and Export"
Login to get access to the exclusive discord channel.
Loading Discord Posts