- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 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)
Читал беовульфа?