-
-
Save alexkonst/e2d558d3382a7f20ce77564898f1bb72 to your computer and use it in GitHub Desktop.
TS homework 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Identifier = string | number | |
// ======= | |
const ReadOperation: symbol = Symbol('Read') | |
const WriteOperation: symbol = Symbol('Write') | |
const UpdateOperation: symbol = Symbol('Update') | |
type Operations = typeof ReadOperation | typeof WriteOperation | typeof UpdateOperation | |
// ======= | |
type Grades = number[] | |
type GradeStatus = 'pass' | 'fail' | |
// ======= | |
type CalculateArea = { | |
(radius: number): number | |
(width: number, height: number): number | |
(a: number, b: number, c: number): number | |
} | |
const caclulateArea: CalculateArea = function (...args: number[]) { | |
switch (args.length) { | |
case 1: { | |
const [radius] = args | |
return Math.PI * Math.pow(radius, 2) | |
} | |
case 2: { | |
const [width, height] = args | |
return width * height | |
} | |
case 3: { | |
const [a, b, c] = args | |
const s = (a + b + c) / 2 | |
return Math.sqrt(s * (s - a) * (s - b) * (s - c)) | |
} | |
default: { | |
throw new Error('arguments mismatch') | |
} | |
} | |
} | |
// ======= | |
type Template = `${bigint}${'px' | '%'}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment