How do you typecast in TypeScript

0 votes

How do I handle typecasting from SymbolInfo to MarkerSymbolInfo in TypeScript for this 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";
        }              

    }
}
May 31 in TypeSript by Logan
• 2,140 points
29 views

1 answer to this question.

0 votes

Casting:

return this.createMarkerStyle(<MarkerSymbolInfo> symbolInfo);

Or

Casting compatible with tsx mode:

return this.createMarkerStyle(symbolInfo as MarkerSymbolInfo);

This is a compile-time cast, and not a runtime cast.

answered Jun 1 by Nina
• 3,020 points

Related Questions In TypeSript

0 votes
1 answer

TypeScript: How do you loop through a dictionary?

To loop over the key/values, use a for ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
45 views
0 votes
1 answer

How to typecast a string to number in TypeScript?

You can use the parseInt or parseFloat functions, or simply use ...READ MORE

answered Jun 9 in TypeSript by Nina
• 3,020 points
9 views
0 votes
1 answer

How do I extend a TypeScript class definition in a separate definition file?

If you don't have control over the ...READ MORE

answered Jun 10 in TypeSript by Nina
• 3,020 points
170 views
0 votes
1 answer

How to create ES6 Map in Typescript

Refer this as an example this.configs = new ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
24 views
0 votes
1 answer

How to set meta tags using Angular universal SSR and ngx-seo plug-in?

first Install the plug-in with npm i ngx-seo ...READ MORE

answered Feb 11 in Others by narikkadan
• 11,280 points
724 views
0 votes
1 answer

How to use next-seo for setting nextjs meta tag with multiple OGP images?

https://github.com/garmeeh/next-seo use this git repo that contains ...READ MORE

answered Feb 24 in Others by narikkadan
• 11,280 points
467 views
0 votes
0 answers

how to sign bitcoin psbt with ledger?

I'm trying to sign a PSBT transaction ...READ MORE

Mar 9 in Blockchain by Soham
• 8,740 points
277 views
0 votes
0 answers

Can't bind to 'ngModel' since it isn't a known property of 'input'

I have this  input in my component ...READ MORE

Apr 29 in Other DevOps Questions by Kichu
• 19,040 points
149 views
0 votes
1 answer
0 votes
1 answer

How do you run TypeScript files from command line?

You can leave tsc running in watch mode using tsc ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
37 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP