Skip to content

Instantly share code, notes, and snippets.

@orta
Last active June 2, 2022 16:56
Show Gist options
  • Save orta/d7dbd4cdb8d1f99c52871fb15db620bc to your computer and use it in GitHub Desktop.
Save orta/d7dbd4cdb8d1f99c52871fb15db620bc to your computer and use it in GitHub Desktop.
My Playground Preview

TSNYC Jan 2020


What is TypeScript?

TypeScript extends JavaScript by adding types.

TypeScript speeds up your development experience by catching errors and providing fixes before you even run your code.

Any browser, any OS, anywhere JavaScript runs. Entirely Open Source.


Your organizers: Dan, Jason, Kirill and Orta'


Meetup Format

  • Summary of TypeScript changes
  • Two or Three 10–20 minute talks: Beginner, Intermediate, Advanced
  • Q&As after each talk

Please use #tsnyc on Twitter, Instagram, etc.

We follow the JSConf Code of Conduct


v3.8 Five main features

  • Import type
  • Private Fields
  • Top Level Await
  • JSDoc Improvements
  • Watch Options

import type

Why?

Guaranteed Side-effect free syntax

Tools like Babel, which don’t type-check can be certain with 100% accuracy
whether to remove the import.

// Look at the JS, this isn't included in the output import {DangerDSLType} from "danger"

declare const myDSL: DangerDSLType

myDSL.bitbucket_cloud

// On the other hand, this one is... import {danger} from "danger" danger.git

// But why?

// TS keeps track of whether an import is a "JS" value // or a TypeScript type. import {DangerDSLJSONType, message} from "danger" message

// Babel cannot do this!

// So now Babel knows that it can always skip these // 'import type' statements import type {DangerUtilsDSL} from "danger"

// Because they can't be used with "JS" values: import type {markdown} from "danger"


import type

Guaranteed Side-effect-y imports

There are folks who want to rely on importing side-effects, but also import a type from that import


// This statement will get erased because of import elision.
import { SomeTypeFoo, SomeOtherTypeBar } from "./module-with-side-effects";

// This statement always sticks around.
import "./module-with-side-effects";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment