- 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)
Rooster 10.12.2022 20:25 # 0
Alina_Poksenova 10.12.2022 20:45 # 0
guest6 12.12.2022 00:29 # 0
Alina_Poksenova 12.12.2022 02:52 # 0
guest6 12.12.2022 03:15 # 0
Читал беовульфа?
CBuHOKYP 12.12.2022 22:46 # 0
Da_xyu_BAC_PA36EPET 15.12.2022 02:26 # 0
_PHP_ 11.12.2022 23:29 # 0