Skip to content

Instantly share code, notes, and snippets.

@CreatiCoding
Created January 27, 2019 07:02
Show Gist options
  • Select an option

  • Save CreatiCoding/613458a4219f267f160d90b7617d3d81 to your computer and use it in GitHub Desktop.

Select an option

Save CreatiCoding/613458a4219f267f160d90b7617d3d81 to your computer and use it in GitHub Desktop.
TypeScript - intersection types simple example
// From https://gist.github.com/Ibro/262ee343ea3a2a244ec76b44f6723713#file-typescript-intersection-type-simple-ts
// Origin code is error code. So I fix it by referencing https://www.typescriptlang.org/docs/handbook/interfaces.html
interface IStudent {
id: string;
age: number;
}
interface IWorker {
companyId: string;
}
let x = <IStudent & IWorker>{};
x.age = 5;
x.companyId = "CID5241";
x.id = "ID3241";
console.log(x);
@CreatiCoding

Copy link
Copy Markdown
Author

result

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment