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
4 changes: 4 additions & 0 deletions src/task_1/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let user: User = new User(19, 'Yaroslav');
user.upAgeByYear();

console.log(user.age);
12 changes: 12 additions & 0 deletions src/task_1/typing.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface ICustom {
user: User;
}

declare var Custom: ICustom;

declare class User {
public age: number;
public name: string;
constructor(a: number, n: string);
public upAgeByYear(): void;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

правильно
3 бала

11 changes: 11 additions & 0 deletions src/task_2/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {SettingValue, Setting} from './setting';

class Example {
public title?: string;
public id?: number;
private _setting: Setting;

constructor(s: Setting) {
this._setting = s;
}
}
14 changes: 14 additions & 0 deletions src/task_2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="ru">

<head>
<meta charset="utf-8">
<title>Заголовок</title>
</head>

<body>
<script data-main="./example.js"
src="https://requirejs.org/docs/release/2.3.6/minified/require.js">
</script>
</body>
</html>
Copy link
Contributor

Choose a reason for hiding this comment

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

Всё правильно
3 бала

13 changes: 13 additions & 0 deletions src/task_2/setting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {SettingValue} from './setting_val';

class Setting {
public key: string;
public value: SettingValue;

constructor(k: string, ov: SettingValue) {
this.key = k;
this.value = ov;
}
}

export {SettingValue, Setting};
9 changes: 9 additions & 0 deletions src/task_2/setting_val.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class SettingValue {
public property1: string;
public property2: string;

constructor(p1: string, p2: string) {
this.property1 = p1;
this.property2 = p2;
}
}
59 changes: 37 additions & 22 deletions src/task_3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,48 @@ class HttpError extends Error {
}
}

function req(url: string): Promise<IUser> {
return fetch(url)
.then((response: Response) => {
if (response.status == 200) {
return response.json();
} else {
throw new HttpError(response);
}
})
async function req(url: string): Promise<IUser> {
const response = await fetch(url);
if(response.status === 200) {
return await response.json()
}
throw new HttpError(response);
// return fetch(url)
// .then((response: Response) => {
// if (response.status == 200) {
// return response.json();
// } else {
// throw new HttpError(response);
// }
// })
}

// Запрашивать логин, пока github не вернёт существующего пользователя.
function getGitHub() {
async function getGitHub() {
let name = prompt("Введите логин на GitHub?", "");

return req(`https://api.github.com/users/${name}`)
.then(user => {
document.write(`Полное имя: ${user.name}, уникальный номер: ${user.id}.`);
return user;
})
.catch(err => {
if (err instanceof HttpError && err.response.status == 404) {
document.write("Такого пользователя не существует.");
} else {
throw err;
}
});
try {
const user = await req(`https://api.github.com/users/${name}`);
document.write(`Полное имя: ${user.name}, уникальный номер: ${user.id}.`);
} catch(err) {
if (err instanceof HttpError && err.response.status == 404) {
document.write("Такого пользователя не существует.");
} else {
throw err;
}
}
// return req(`https://api.github.com/users/${name}`)
// .then(user => {
// document.write(`Полное имя: ${user.name}, уникальный номер: ${user.id}.`);
// return user;
// })
// .catch(err => {
// if (err instanceof HttpError && err.response.status == 404) {
// document.write("Такого пользователя не существует.");
// } else {
// throw err;
// }
// });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

3 бала


getGitHub();