devmeetings-react-ts-fork
  • Devmeeting React + Typescript
  • Speed dating
  • Typescript
    • It's just JavaScript
    • Basic types
    • Typing objects
    • Typing functions
    • Modules
    • Generics
    • Tasks
  • Hello React
    • Quick look around
    • The first component
    • JSX
    • Tasks
  • Components & Props
    • Small components
    • Passing data to a component
    • Loops in JSX
    • Tasks
  • Stateful components
    • Handling events
    • Components with internal state
    • Talking to a parent component
    • Smart and dumb components
    • Before the break
    • Tasks
  • Side-effects and context
    • Side-effects
    • Prop drilling
    • Using context
    • Tasks
  • What's next
    • Styling
    • Learning component's lifecycle
    • State Management
Powered by GitBook
On this page
  • Importing npm modules
  • Resources

Was this helpful?

  1. Typescript

Modules

Both modern JS and TypeScript support modules. Each file is a module, than can export some properties:

// src/foo.ts
export const foo = 12

Which then are imported in another file:

// src/bar.ts
import { foo } from "./foo"

Each file can also have a default export, which means you don't have to name the exported property:

// src/baz.ts
export default 42;

You can name it when importing:

// src/bar.ts
import Baz from "./baz";

You can also mix both styles:

import DefaultExport, { namedExport1, namedExport2 } from "./a-file"

Importing npm modules

Importing code installed via npm is done by specifying the package name instead of relative path:

import React from "react"

Some (usually older) packages have no default export and have to be imported as a group of properties;

import * as _ from "underscore"

Resources

PreviousTyping functionsNextGenerics

Last updated 5 years ago

Was this helpful?

Modules
export default considered harmful