Skip to content

Tag: typescript

Casting a number to a string in TypeScript

Which is the the best way (if there is one) to cast from number to string in Typescript? In this case the compiler throws the error: Type ‘number’ is not assignable to type ‘string’ Because location.hash is a string. So which method is better? Answer “Casting” is different …

Is there destructor in typeScript

Is there destructor in TypeScript? If not, how can I delete an object? I tried destructor() and ~ClassName() but it didn’t work. Answer JavaScript uses garbage collection to automatically delete objects when they are no longer referenced. There is no concept of destructors or finalizers. You can’t…

typescript – cloning object

I have a super class that is the parent (Entity) for many subclass (Customer, Product, ProductCategory…) I’m looking to clone dynamically an object that contains different sub objects in Typescript. In example : a Customer that has different Product who has a ProductCategory In order to clone the …

How to call array reduce in TypeScript?

I am trying to find the largest item in an array. It was simple enough to solve using the straight-forward, simple, clean, elegant, fast method – iterating the array: But that’s not cool Then, rather than solving the problem using the easy way, i wanted to try to solve it using .reduce: And it&#82…

Is any JavaScript code a valid TypeScript code?

Currently I’ve started to learn TypeScript. From the documents I’ve studied for TypeScript, I saw some samples that pure JavaScript code could be compiled as TypeScript code. My question is: Is TypeScript language designed in a way that any JavaScript code will be a valid TypeScript code? i.e. is …