Skip to content

Instantly share code, notes, and snippets.

@spksoft
Created September 8, 2017 10:35
Show Gist options
  • Save spksoft/19c9bb287312156673ce9a706d79be37 to your computer and use it in GitHub Desktop.
Save spksoft/19c9bb287312156673ce9a706d79be37 to your computer and use it in GitHub Desktop.
type User = {
firstname: string,
lastname: string
};
type NumberOrStringOrStudent = string | number | User;
let myValue: NumberOrStringOrStudent;
const sampleUser: User = {
firstname: 'Sippakorn',
lastname: 'Raksakiart'
};
myValue = sampleUser;
myValue = 12;
myValue = 'HelloWorld';
myValue = true; // Error `Type 'true' is not assignable to type 'NumberOrStringOrStudent'.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment