Klaus Nji Klaus Nji - 2 years ago 203
TypeScript Question

TypeScript or JavaScript type casting

How does one handle type casting in TypeScript or Javascript?

Say I have the following TypeScript code:

module Symbology {

export class SymbolFactory {

createStyle( symbolInfo : SymbolInfo) : any {
if (symbolInfo == null)
return null;

if (symbolInfo.symbolShapeType === "marker") {

// how to cast to MarkerSymbolInfo
return this.createMarkerStyle((MarkerSymbolInfo) symbolInfo);

createMarkerStyle(markerSymbol : MarkerSymbolInfo ): any {
throw "createMarkerStyle not implemented";


is a base class. How do I handle typecasting from
in TypeScript or Javascript?

Answer Source

You can cast like this:

return this.createMarkerStyle(<MarkerSymbolInfo> symbolInfo);

Just remember that this is a compile-time cast, and not a runtime cast.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download