Skip to content

Instantly share code, notes, and snippets.

@alexkonst
Last active April 21, 2025 20:37
Show Gist options
  • Save alexkonst/e2d558d3382a7f20ce77564898f1bb72 to your computer and use it in GitHub Desktop.
Save alexkonst/e2d558d3382a7f20ce77564898f1bb72 to your computer and use it in GitHub Desktop.
TS homework 2
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