Skip to content

Instantly share code, notes, and snippets.

@carlrip
Created December 17, 2019 18:23
Show Gist options
  • Save carlrip/970d02d39c126ffc6d922eb303c5e902 to your computer and use it in GitHub Desktop.
Save carlrip/970d02d39c126ffc6d922eb303c5e902 to your computer and use it in GitHub Desktop.
const assertions - literals
function logStatus(status: "LOADING" | "LOADED") {
console.log(status);
}
const Status = {
Loading: "LOADING",
Loaded: "LOADED",
};
logStatus(Status.Loading); // 💥 - Type error - Argument of type 'string' is not assignable to parameter of type '"LOADING" | "LOADED"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment