Skip to content

Instantly share code, notes, and snippets.

@Rolando-Barbella
Last active March 20, 2023 14:56
Show Gist options
  • Save Rolando-Barbella/3b5d295668cb340af0e3f094859f3ee6 to your computer and use it in GitHub Desktop.
Save Rolando-Barbella/3b5d295668cb340af0e3f094859f3ee6 to your computer and use it in GitHub Desktop.
interface Worker {
name: string,
surname: string,
deparment: 'ENGINEERING' | 'SALES',
skills: Array<string>,
};
interface Developer extends Worker {
type: 'FRONT-END' | 'FULL-STACK',
javascriptLevel: number,
skills: Array<string>,
};
interface SalesRepresantive extends Worker {
type: 'INTERNATIONAL-SALES' | 'LOCAL-SALES',
closedDeals: number,
skills: Array<string>,
};
let workers = [
{
name: 'James',
surname: 'Jhonson',
deparment: 'ENGINEERING',
type: 'FRONT-END',
skills: ['ReactJs', 'CSS'],
javascriptLevel: 8,
},
{
name: 'Adriana',
surname: 'Lopez',
deparment: 'SALES',
type: 'INTERNATIONAL-SALES',
skills: ['Marketing', 'Writting'],
closedDeals: 93,
}
];
function isFrontEndDev(worker: Developer | SalesRepresantive): worker is Developer {
return (worker as Developer).javascriptLevel !== undefined
};
let isSalesPerson: Array<SalesRepresantive | Developer> = workers.filter((worker): worker is SalesRepresantive => {
if(worker.skills.includes('ReactJs')) return false;
return true;
});
let getGihubUsers = async (): Promise<void> => {
try {
await fetch('https://api.github.com/users')
.then(response => response.json())
.then(users => console.log(users))
} catch (e) {
console.error(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment