Skip to content

Instantly share code, notes, and snippets.

View diegogriep's full-sized avatar
🎯
Focusing

Diego Griep diegogriep

🎯
Focusing
View GitHub Profile
interface DefaultResponse<T> {
code: number;
content: T;
timestamp: string;
valid: boolean;
}
interface Driver {
id: number;
name: string;
interface DriverF1 {
firstName: string;
lastName: string;
}
const newDriverF1 = <T extends DriverF1>(obj: T) => {
return {
...obj,
fullName: `${obj.firstName} ${obj.lastName}`
}
interface DriverF1 {
firstName: string;
lastName: string;
}
const newDriverF1 = (obj: DriverF1) => {
return {
...obj,
fullName: `${obj.firstName} ${obj.lastName}`
}
const createArray = <A, B = number>(a: A, b: B) => {
return [a, b];
}
let otherArray = createArray<string | null>("Junho", 6);
let showArrayWithNumberNBoolean = createArray<string, boolean | null>('Brasil', 2020);
//Argument of type '2020' is not assignable to parameter of type 'boolean'
const createArray = <A, B>(a: A, b: B) => {
return [a, b];
}
let showArray = createArray('Brasil', 2020);
function returnLastOne<T>(param: Array<T>): T {
return param.pop();
}
//ou
function returnLastOne<T>(param: T[]) { //implícito retorna tipo T
return param.pop();
}
function returnTheSameArguments<T>(param: T): T {
return param;
}
let showMessage = returnTheSameArguments("Qual conhecimento você compartilhou hoje?");
function returnTheSameArguments(arg: number): number {
return arg;
}
function ruleOfThree (had, got, have) {
return have * got / had;
}