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, 2022 in TypeSript by Logan
• 2,140 points
615 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, 2022 by Nina
• 3,060 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, 2022 in TypeSript by Nina
• 3,060 points
4,847 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, 2022 in TypeSript by Nina
• 3,060 points
526 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, 2022 in TypeSript by Nina
• 3,060 points
2,668 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, 2022 in TypeSript by Nina
• 3,060 points
793 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, 2022 in Others by narikkadan
• 63,680 points
2,175 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, 2022 in Others by narikkadan
• 63,680 points
6,092 views
0 votes
0 answers

how to sign bitcoin psbt with ledger?

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

Mar 9, 2022 in Blockchain by Soham
• 9,710 points
1,645 views
0 votes
1 answer

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

Just add this in the app.module.ts file: import { FormsModule ...READ MORE

answered Apr 30, 2022 in Other DevOps Questions by narikkadan
• 63,680 points
4,402 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, 2022 in TypeSript by Nina
• 3,060 points
883 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP