Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created March 27, 2017 18:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Ibro/ba763b1c91d28acdac08efee547dfbb3 to your computer and use it in GitHub Desktop.
Union Types in TypeScript - Interfaces
interface IStudent {
id: string;
age: number;
}
interface IWorker {
companyId: string;
}
type IUnionType = IStudent | IWorker;
let p: IUnionType = {
id: 'ID3241',
age: 21
};
// p = 3; // Type '3' is not assignable to type 'IUnionType'
p = {
companyId: 'cid993'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment