Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

literal types typescript

type Easing = "ease-in" | "ease-out" | "ease-in-out";
 
class UIElement {
  animate(dx: number, dy: number, easing: Easing) {
    if (easing === "ease-in") {
      // ...
    } else if (easing === "ease-out") {
    } else if (easing === "ease-in-out") {
    } else {
      // It's possible that someone could reach this
      // by ignoring your types though.
    }
  }
}
 
let button = new UIElement();
button.animate(0, 0, "ease-in");
button.animate(0, 0, "uneasy");
Argument of type '"uneasy"' is not assignable to parameter of type 'Easing'.
Argument of type '"uneasy"' is not assignable to parameter of type 'Easing'.
Try
Comment

PREVIOUS NEXT
Code Example
Typescript :: conventional commits cheat sheet 
Typescript :: how to compare two date in typescript 
Typescript :: what is data type in data structure 
Typescript :: void function typescript 
Typescript :: pass command line arguments with spaces cmd 
Typescript :: Why do we use fragments in react? 
Typescript :: invoke lambda after cdk deploy 
Typescript :: git merge all previous commits on a branch 
Typescript :: typescript to java converter 
Typescript :: ts object field from variable 
Typescript :: subscribe in angular 10 
Typescript :: angular pass parameter to click function 
Typescript :: nuxtServerInit nuxt 3 
Typescript :: google places auto-complete 
Typescript :: how to create multiple sheets in excel using python in openpyxml 
Typescript :: angular bind colspan to ts variable 
Typescript :: typeorm generated 
Typescript :: addObjects giving a fatal error when pushing data to algolia 
Typescript :: Display Popular Posts laravel 
Typescript :: typescript `is a` function determine type 
Typescript :: sql concepts interview questions 
Typescript :: does casting have a higher precedence than dots java 
Typescript :: check if package exists inside the device adb 
Typescript :: method swap to the Pair class of that swaps the first and second elements value of the pair in generic Pair class in java 
Typescript :: how did mississauga get its name 
Typescript :: Do feral cats have rabies? 
Typescript :: see all github issue comments i made site:stackoverflow.com 
Typescript :: typescript unions 
Typescript :: css animation for beginners 
Typescript :: nativescript display image from web 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =