Skip to content

Instantly share code, notes, and snippets.

@porfirion
Created March 14, 2019 17:44
Show Gist options
  • Save porfirion/d3a2e9eb02440f3f3efd9a49b0245073 to your computer and use it in GitHub Desktop.
Save porfirion/d3a2e9eb02440f3f3efd9a49b0245073 to your computer and use it in GitHub Desktop.
var str: "value" = "test" // error
var str2: "value" = "test" as "value" // ok
var str3: string = "my string" // assignment of healthy man
var str4: string = {} // error
var str5: string = {} as string // OK
var str6: string = {} as "anything" // OK!!
type Duumvirate = 1 | 2
var int: Duumvirate = 3 as 1 // OK!!!
// idea of unions
type Tristate = "TRUE"|"FALSE"|"NONE";
function foo(param: Tristate) {
return "enhanced: " + param;
}
let validInput = "NONE";
foo(validInput as Tristate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment