Skip to content

Instantly share code, notes, and snippets.

@tamert
Last active September 12, 2021 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamert/539c9f9c0b8ad00a7ebf8a68a7b444aa to your computer and use it in GitHub Desktop.
Save tamert/539c9f9c0b8ad00a7ebf8a68a7b444aa to your computer and use it in GitHub Desktop.
Record 2
interface Book {
id: number;
title: string;
header?: string;
body: string;
date?: Date;
}
class Writer {
name: string | null = null;
books: Record<'famous' | 'infamous', Book | null> = { famous: null, infamous: null };
}
const data: Writer = new Writer();
data.name = 'Douglas Adams';
data.books['famous'] = {
id: 1,
title: 'The Ultimate Hitchhiker`s Guide',
body: 'Seconds before the Earth is demolished for a galactic freeway, Arthur Dent is saved by Ford Prefect, a researcher for the revised Guide. Together they stick out their thumbs to the stars and begin a wild journey through time and space. The Restaurant at the End of the Universe',
};
console.log(data);
/**
Writer: {
"name": "Douglas Adams",
"books": {
"famous": {
"id": 1,
"title": "The Ultimate Hitchhiker`s Guide",
"body": "Seconds before the Earth is demolished for a galactic freeway, Arthur Dent is saved by Ford Prefect, a researcher for the revised Guide. Together they stick out their thumbs to the stars and begin a wild journey through time and space. The Restaurant at the End of the Universe"
},
"infamous": null
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment