Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/task_1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
* который написан в функции logObj компилировался и исполнялся корректно
*/

type FooType = unknown;
type BarType = unknown;
type FooType = {
stringProp: string,
numberProp: number,
barObject: BarType,
};

type BarType = {
stringsArrayProp: Array<string>,
numbersOrDatesArrayProp: Array<number | Date>,
functionProp: Function,
};

export const fooObjects: FooType[] = [
{
Expand Down
9 changes: 9 additions & 0 deletions src/task_3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@
function add(x: string, y: string): string;
function add(x: number, y: number): number;

function add(x, y) {
if (typeof x === "number" && typeof y === "number") {
return Number(x + y);
}
if (typeof x === "string" && typeof y === "string") {
return (x + y).toString();
}
}

add('20', '21'); //2021
add(20, 21); //41
24 changes: 24 additions & 0 deletions src/task_4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ interface IFoo {
a: number
b: string
}

/* Пример interface:
Только описывает
interface IVegetable {
name: string;
getCalories(): number;
}
Это конкретный класс
class Tomato implements IVegetable {
name: string = 'Tomato';
getCalories() {
return 18;
}
}
*/
//Интерфейс может быть назван в выражении extends или implement, но псевдоним типа для литерала типа объекта не может.
//Интерфейс может иметь несколько объединенных объявлений, но псевдоним типа для литерала типа объекта не может.

type FooType = {
a: number
b: string
};

/*
Type - это лишь типизация какой-то переменной, как правило, нестандартной, Например, мы хотим определить тип, который будет описывать степень готовности стейков:
type SteakRoast = 'medium' | 'rare' | 'welldone';
Таким образом, мы можем присвоить переменной типа SteakRoast только эти предопределённые значения.
*/

2 changes: 1 addition & 1 deletion src/task_5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function logPerson(person: Person) {
console.log(` - ${person.name}, ${person.age}, ${additionalInformation}`);
}

export function filterUsers(persons: Person[], criteria: User): User[] {
export function filterUsers(persons: Person[], criteria: User | Object): User[] {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно написать сам тип. Значение Object - это абстрактное значение.

return persons.filter(isUser).filter((user) => {
const criteriaKeys = Object.keys(criteria);
return criteriaKeys.every((fieldName) => {
Expand Down