Untitled
unknown
typescript
2 years ago
1.7 kB
9
Indexable
type Coffee = 'espresso' | 'latte' | 'cappuccino' | 'black';
interface SuperPower {
name: string;
description: string;
}
interface GoodProgrammer {
name: string;
yearsOfExperience: number;
favoriteProgrammingLanguage: 'TypeScript' | 'JavaScript' | 'Python' | 'Java' | 'Others...';
coffeeConsumptionPerDay: number;
favoriteCoffeeType: Coffee;
hasRubberDuck: boolean; // Rubber duck debugging!
canCodeWithoutGoogle: boolean; // Truly a superpower
spokenLanguages: string[]; // Not programming languages, but real languages!
superPowers: SuperPower[]; // Because every good programmer has super powers
hasEverDreamtInCode: boolean;
mostUsedPhrase: string; // "It works on my machine!"
debugMethod: 'print' | 'console.log' | 'prayer' | 'dark magic';
prefersTabsOrSpaces: 'tabs' | 'spaces' | 'who cares, as long as it works';
favoriteError: string; // "Unexpected token < in JSON at position 0"
}
// Example:
const johnDoe: GoodProgrammer = {
name: 'John Doe',
yearsOfExperience: 5,
favoriteProgrammingLanguage: 'TypeScript',
coffeeConsumptionPerDay: 5,
favoriteCoffeeType: 'latte',
hasRubberDuck: true,
canCodeWithoutGoogle: false,
spokenLanguages: ['English', 'Binary'],
superPowers: [
{ name: 'Infinite patience', description: 'Can wait for npm install to finish without checking Twitter' },
{ name: 'Bug whisperer', description: 'Can talk to bugs and convince them to leave' }
],
hasEverDreamtInCode: true,
mostUsedPhrase: 'It works on my machine!',
debugMethod: 'console.log',
prefersTabsOrSpaces: 'spaces',
favoriteError: 'Cannot read property \'undefined\' of undefined'
};
Editor is loading...