K
K
Kirill Novak2019-01-28 21:05:01
JavaScript
Kirill Novak, 2019-01-28 21:05:01

How to make custom TypeScript types (Number, Array, Object, Boolean)?

Can you please help. I'm switching from JS to TS, and immediately got into a stupor. How to write a custom object (type) that can be of the Number, Boolean, Object, and Array types at once.
Main idea: to write an abstraction, roughly speaking, for the server response, the server can respond with a number, an array, a Json Object and a boolean. We need to be able to handle the response in the same way as with the main types (add a number, sort an array, etc.), but at the same time add common methods for abstraction, like getStatusCode (get the response code), getHeaders(), etc. e
Here is what is already there, it works, but VS code swears, says that the original type does not have those properties that I add to it later.
https://pastebin.com/e8e4Wsab
The code itself works. But there is a mistake, and it hurts the eye.
VN5lWEBdcp4.jpg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question