- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
export const asObject = <K extends string> (x: unknown) =>
(x !== null && typeof x === 'object' ? x : {}) as { [P in K]: unknown }
interface Krevetko {
curvature: number
}
export const isKrevetko = (x: unknown): x is Krevetko => {
const { curvature } = asObject<keyof Krevetko>(x)
return typeof curvature === 'number'
}
const userInput: unknown = 'хз че тут'
if (!isKrevetko(userInput)) {
throw new Error('Идите нахуй, плз')
}
console.info('Йа креветко: ', userInput.curvature)
Читал беовульфа?