aizatto.com
  • aizatto.com
  • Table of Contents
  • Portfolio, Projects, Tools, Toys
  • Interview Guide
    • Choosing A Company
    • Job Boards
    • Practice
    • Technical Interview Cheatsheet
    • Interview Process
      • Questions to Ask
      • Coding
      • Soft Skills
      • Rejection
      • Negotiation / Deciding
      • Accepting, Joining
    • FAQ
  • Engineering Code
    • Communication
    • Different Types of Coding
    • Commit Messages
    • Reviewing Code
      • Requesting Changes
    • Writing Code
      • Consistency
      • Writing for a code base of 1,000,000+ Lines
      • Write Code Knowing It Will Be Refactored
      • Naming
        • Versioning
        • Create Searchable Names
      • Commenting
        • Don't commit commented code
      • Make It Easy To Reproduce
      • Scripts
      • 80 character limit
      • Exit Early
      • Be careful of enum in switch statements
      • Be careful about chaining conditions
      • Be careful of chaining ternary operators
      • Write Code Knowing You Will be Blamed
      • Hacks
      • Bad Practices
      • Logs
      • Time
      • Other rules
    • Engineering Code
    • Engineering Data
    • Pipelines
    • Configuration Files
    • Site Reliability Engineering (SRE)
    • Best Engineers
  • Engineering Management
    • Hiring
    • New Reports
    • 1:1s
      • Calibration
      • Expectations
      • Mentorship / Learning / Growing
      • Task Management
      • Teams
    • Interviewing Candidates
    • Messenger Groups
    • Resources
  • Why GitBook?
  • Getting into Tech
    • Terminology
  • Personal Goals
  • Daily Drivers
  • Contacting Me
  • Notes
    • JavaScript
      • Array
      • Async & Await / Promises
      • Booleans
      • Collections
      • Cons/Dislikes
      • fetch
      • Map
      • Modules
      • Object
      • Regex
      • Set
      • Style Guides
      • Versions
    • Node.js
      • Best Practices
      • DraftJS
      • eslint
      • GraphQL
      • Relay
      • Hapi
      • Knex
      • Koa
      • TypeScript
      • Webservers
    • Technical Due Diligence
    • Archive
      • Amazon Echo Dot (3rd Gen) with clock
      • Apple
        • AirPods Pro
        • Apple Notes
        • Apple Watch Series 4
        • iPad Pro 11" 2018
        • MacBook Pro 15" 2017
        • macOS
      • Audible
      • Balance
        • Growth vs Contentment
        • Leading vs Following
        • Mindful vs Mindless
        • New vs Old
      • Bags
      • Bandwidth Requirements
      • B2B/B2C
      • Blockchain
      • Board Games
        • Bang
      • Broadway
      • Cheap, Good, Fast
      • CLI
        • git
        • ufw
        • xargs
      • Cloud Providers
        • GCP
      • Communication
        • Asking Questions / Making Requests
        • Making Edits
        • Synchronous vs Asynchronous
        • Change Management
        • Problem Definition
      • Company
        • All Hands
        • The Problematic CTO
        • Organizational Structure
      • Content Creation
      • COVID 19/Corona Virus
      • Coworking Spaces
      • Daily Routine
      • Dating
      • Displays / Monitors
      • DNS
      • Domain Registrars
      • Driving
      • eCommerce
      • Empire Building
      • Facebook for Developers
      • Fever
      • Fiverr
      • Flights
      • Gaming Tablet
      • GitHub
      • GTD
      • Go Lang
      • Headsets
      • Hiking
        • Chamang Waterfalls
        • Kanching Waterfalls
        • Kota Damansara Community Forest Reserve
        • Sungai Chilling
      • Home Device Calling
      • iCalendar
      • Keyboards
        • Ergodox Ez
      • Malaysia Insurance
      • Mental Health Malaysia
      • Multiroom Wireless Speaker System
      • Musicals
      • Mouse
      • Movies
      • Password Managers
      • Phabricator
      • Physical Health
        • Cardio
      • Podcasts
      • Programming Bootcamps
      • Property
      • Productivity
        • Note Taking
      • Redang
      • Relationships
      • Referral Codes
      • Remote Calls
      • Remote Work
        • Comparison
      • Road Trips
      • Ruby / Ruby on Rails
      • Scraping
      • Slack
      • Stripe
      • Singapore
      • UX
      • Venture Builder
      • Video Games
      • Virtual Personal Assistant
      • VPN
      • WebDAV / CalDAV
      • WebSocket
      • Withings
      • Xiaomi Roborock Mijia
      • Old Hardware
        • Netgear R7000P
      • Web Development
        • React
        • SSO Providers
      • Software Engineering
        • Software Architectures
          • Monolithic
          • Non-Monolithic
            • Microservice
            • FaaS (Functions as a Service) or Serverless
        • Repository Management
  • More on Notion
Powered by GitBook
On this page
  • Versioning
  • Compiler Options
  • Sharing between models
  • Typing
  • Objects
  • React

Was this helpful?

  1. Notes
  2. Node.js

TypeScript

Pros:

  • Useful for preventing me from pushing the quick hacks I'm trying to commit in JavaScript.

Cons:

  • Modules you depend on may not have typescript definitions

    • To avoid typing, you may have to go backwards const ... = require()

  • Definition hell

Versioning

Node

TypeScript Target

Support

6.17

es5

AWS Lambda Node v6.10 support

es6

8.10-9.11.2

8.10-9.11.2

AWS Lambda Node v8.10 support

10-nightly

AWS Lambda Node v10.x support

General Rules:

  • If you are targeting for web set target to es5

  • If you targeting for AWS Lambda, set your target to es2018

    • Node.js v10.x supports es2018

  • If you are targeting for local and using the latest node, go for es2019

    • I'm assuming you can target for esnext as well as it wouldn't make sense to write code that the latest Node.js could write...but I could be wrong

Compiler Options

Enable:

  • declaration: true when you want to share a Typescript code across modules

  • jsx: react when you want to share a React component across modules

Sharing between models

Enable in your compiler option:

  • declaration: true

  • jsx: react

Typing

function and object destructuring

function Render(props: {uri?: string}) {
function toJSON(
  value: any,
  { pretty }: { pretty: boolean }
) {
  const indent = pretty ? 4 : 0;
  return JSON.stringify(value, null, indent);
}

Objects

interface LRUHashMap  {
  [value: number]: DoublyLinkedList;
}

class LRUHash {
  private hash: LRUHashMap;

  construct() {
    this.hash = {};
  }
}

Enums cannot be keys

This fails:

const enum Key { ... }
const config: { [key: Key]: string } = {};

Keys can only be string or number.

Use Map instead:

const enum Key { ... }
const config = new Map<Key, string>();

React

children

interface Props {
  children?: any;
}

useRef

export default function UriField() {
  const [uri, setURI] = useState<string | null>(null);
  const inputRef = useRef<HTMLInputElement>(null);
  const onClick = () => {
    if (!inputRef ||
        !inputRef.current) {
      return;
    }

    setURI(inputRef.current.value);
  }

  return (
    <>
      <input ref={inputRef} type="text" />
      <input onClick={onClick} type="submit" value="Submit"/>
    </>
  );
}
PreviousKoaNextWebservers

Last updated 6 years ago

Was this helpful?

Recommended

https://www.typescriptlang.org/docs/handbook/compiler-options.html
https://www.sitepen.com/blog/typescript-cheat-sheet
https://mariusschulz.com/blog/typing-destructured-object-parameters-in-typescript
https://github.com/sw-yx/react-typescript-cheatsheet
https://github.com/Microsoft/TypeScript/issues/6471#issuecomment-171456118
es2016
es2017
es2018
es2019