Type Program[] is not assignable to string[]TypeScript Converting a String to a numberHow to get the size of a filtered (piped) set in angular2Angular2 and TypeScript: error TS2322: Type 'Response' is not assignable to type 'UserStatus'Cast int to enum strings in TypescriptAngular Promise<void>' is not assignable to typeType 'PersonAddress[]' is not assignable to type 'Observable<PersonAddress[]>' in angular 2Promise argument type is not assignableAutomatically assign a Typescsript class to a JSON objectType '[]' is not assignable to type 'ShoppingCartItem[]'Type 'Observable<Entity[]>' is not assignable to type 'Entity[]'

Why do radiation hardened IC packages often have long leads?

Teaching a class likely meant to inflate the GPA of student athletes

Why Does Mama Coco Look Old After Going to the Other World?

Can a human be transformed into a Mind Flayer?

How to hide rifle during medieval town entrance inspection?

Varying the size of dots in a plot according to information contained in list

bash vs. zsh: What are the practical differences?

How to prove a 4D vector is a 4-Vector?

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

First sign that you should look for another job?

Who won a Game of Bar Dice?

Was Self-modifying-code possible just using BASIC?

Did Apple bundle a specific monitor with the Apple II+ for schools?

If there's something that implicates the president why is there then a national security issue? (John Dowd)

Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?

Can we completely replace inheritance using strategy pattern and dependency injection?

I have a problematic assistant manager, but I can't fire him

How do we say "within a kilometer radius spherically"?

How do free-speech protections in the United States apply in public to corporate misrepresentations?

I've been given a project I can't complete, what should I do?

Increase speed altering column on large table to NON NULL

UTC timestamp format for launch vehicles

How can I make 12 tone and atonal melodies sound interesting?

Are polynomials with the same roots identical?



Type Program[] is not assignable to string[]


TypeScript Converting a String to a numberHow to get the size of a filtered (piped) set in angular2Angular2 and TypeScript: error TS2322: Type 'Response' is not assignable to type 'UserStatus'Cast int to enum strings in TypescriptAngular Promise<void>' is not assignable to typeType 'PersonAddress[]' is not assignable to type 'Observable<PersonAddress[]>' in angular 2Promise argument type is not assignableAutomatically assign a Typescsript class to a JSON objectType '[]' is not assignable to type 'ShoppingCartItem[]'Type 'Observable<Entity[]>' is not assignable to type 'Entity[]'






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have the class below. What I'd like to do is filter for the active programs and inactive programs and then get the program names, as an array of strings, for those programs.



Here is the Program class:



export class Program 
ID: number;
ProgramDescription: string;
ProgramName: string;
ProgramStatus: string;
FiscalYear: string;
SupervisorID: string;
DBN: string;
IsActive: string;



Here are the methods I wrote in the service:



getPrograms(): Observable<Program[]> 
return this.httpClient.get<Program[]>(environment.apiBaseURL + 'api/Program')
.pipe(
map(data => data)
);


getActivePrograms(): Observable<Program[]>
return this.getPrograms()
.pipe(
map(data => data.filter(program => program.IsActive === 'Y'))
);


getActiveProgramNames(): Observable<string[]>
return this.getActivePrograms()
.pipe(
map(data => data.filter(program => program.ProgramName.toString())
);



In getActiveProgramNames(), I'm getting the following error:



Type Program[] is not assignable to type string[]









share|improve this question
























  • I want to cast all of the ProgramNames to an array of string.

    – rds80
    Mar 24 at 20:45







  • 4





    filter isn't going to do that for you. map can.

    – R. Richards
    Mar 24 at 20:46











  • I think @R.Richards is right and you should replace the filter with a map as filter returns a collection of the same type: Program[].

    – adz5A
    Mar 24 at 20:46












  • Is this the right code to do that: map(data => data.map(program => program.ProgramName.toString()))

    – rds80
    Mar 24 at 20:50

















0















I have the class below. What I'd like to do is filter for the active programs and inactive programs and then get the program names, as an array of strings, for those programs.



Here is the Program class:



export class Program 
ID: number;
ProgramDescription: string;
ProgramName: string;
ProgramStatus: string;
FiscalYear: string;
SupervisorID: string;
DBN: string;
IsActive: string;



Here are the methods I wrote in the service:



getPrograms(): Observable<Program[]> 
return this.httpClient.get<Program[]>(environment.apiBaseURL + 'api/Program')
.pipe(
map(data => data)
);


getActivePrograms(): Observable<Program[]>
return this.getPrograms()
.pipe(
map(data => data.filter(program => program.IsActive === 'Y'))
);


getActiveProgramNames(): Observable<string[]>
return this.getActivePrograms()
.pipe(
map(data => data.filter(program => program.ProgramName.toString())
);



In getActiveProgramNames(), I'm getting the following error:



Type Program[] is not assignable to type string[]









share|improve this question
























  • I want to cast all of the ProgramNames to an array of string.

    – rds80
    Mar 24 at 20:45







  • 4





    filter isn't going to do that for you. map can.

    – R. Richards
    Mar 24 at 20:46











  • I think @R.Richards is right and you should replace the filter with a map as filter returns a collection of the same type: Program[].

    – adz5A
    Mar 24 at 20:46












  • Is this the right code to do that: map(data => data.map(program => program.ProgramName.toString()))

    – rds80
    Mar 24 at 20:50













0












0








0








I have the class below. What I'd like to do is filter for the active programs and inactive programs and then get the program names, as an array of strings, for those programs.



Here is the Program class:



export class Program 
ID: number;
ProgramDescription: string;
ProgramName: string;
ProgramStatus: string;
FiscalYear: string;
SupervisorID: string;
DBN: string;
IsActive: string;



Here are the methods I wrote in the service:



getPrograms(): Observable<Program[]> 
return this.httpClient.get<Program[]>(environment.apiBaseURL + 'api/Program')
.pipe(
map(data => data)
);


getActivePrograms(): Observable<Program[]>
return this.getPrograms()
.pipe(
map(data => data.filter(program => program.IsActive === 'Y'))
);


getActiveProgramNames(): Observable<string[]>
return this.getActivePrograms()
.pipe(
map(data => data.filter(program => program.ProgramName.toString())
);



In getActiveProgramNames(), I'm getting the following error:



Type Program[] is not assignable to type string[]









share|improve this question
















I have the class below. What I'd like to do is filter for the active programs and inactive programs and then get the program names, as an array of strings, for those programs.



Here is the Program class:



export class Program 
ID: number;
ProgramDescription: string;
ProgramName: string;
ProgramStatus: string;
FiscalYear: string;
SupervisorID: string;
DBN: string;
IsActive: string;



Here are the methods I wrote in the service:



getPrograms(): Observable<Program[]> 
return this.httpClient.get<Program[]>(environment.apiBaseURL + 'api/Program')
.pipe(
map(data => data)
);


getActivePrograms(): Observable<Program[]>
return this.getPrograms()
.pipe(
map(data => data.filter(program => program.IsActive === 'Y'))
);


getActiveProgramNames(): Observable<string[]>
return this.getActivePrograms()
.pipe(
map(data => data.filter(program => program.ProgramName.toString())
);



In getActiveProgramNames(), I'm getting the following error:



Type Program[] is not assignable to type string[]






angular typescript angular6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 20:46







rds80

















asked Mar 24 at 20:42









rds80rds80

1469




1469












  • I want to cast all of the ProgramNames to an array of string.

    – rds80
    Mar 24 at 20:45







  • 4





    filter isn't going to do that for you. map can.

    – R. Richards
    Mar 24 at 20:46











  • I think @R.Richards is right and you should replace the filter with a map as filter returns a collection of the same type: Program[].

    – adz5A
    Mar 24 at 20:46












  • Is this the right code to do that: map(data => data.map(program => program.ProgramName.toString()))

    – rds80
    Mar 24 at 20:50

















  • I want to cast all of the ProgramNames to an array of string.

    – rds80
    Mar 24 at 20:45







  • 4





    filter isn't going to do that for you. map can.

    – R. Richards
    Mar 24 at 20:46











  • I think @R.Richards is right and you should replace the filter with a map as filter returns a collection of the same type: Program[].

    – adz5A
    Mar 24 at 20:46












  • Is this the right code to do that: map(data => data.map(program => program.ProgramName.toString()))

    – rds80
    Mar 24 at 20:50
















I want to cast all of the ProgramNames to an array of string.

– rds80
Mar 24 at 20:45






I want to cast all of the ProgramNames to an array of string.

– rds80
Mar 24 at 20:45





4




4





filter isn't going to do that for you. map can.

– R. Richards
Mar 24 at 20:46





filter isn't going to do that for you. map can.

– R. Richards
Mar 24 at 20:46













I think @R.Richards is right and you should replace the filter with a map as filter returns a collection of the same type: Program[].

– adz5A
Mar 24 at 20:46






I think @R.Richards is right and you should replace the filter with a map as filter returns a collection of the same type: Program[].

– adz5A
Mar 24 at 20:46














Is this the right code to do that: map(data => data.map(program => program.ProgramName.toString()))

– rds80
Mar 24 at 20:50





Is this the right code to do that: map(data => data.map(program => program.ProgramName.toString()))

– rds80
Mar 24 at 20:50












1 Answer
1






active

oldest

votes


















1














Try with map



getActiveProgramNames(): Observable<string[]> 
return this.getActivePrograms()
.pipe(
map(data => data.map(program => program.ProgramName.toString())
);






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328378%2ftype-program-is-not-assignable-to-string%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Try with map



    getActiveProgramNames(): Observable<string[]> 
    return this.getActivePrograms()
    .pipe(
    map(data => data.map(program => program.ProgramName.toString())
    );






    share|improve this answer



























      1














      Try with map



      getActiveProgramNames(): Observable<string[]> 
      return this.getActivePrograms()
      .pipe(
      map(data => data.map(program => program.ProgramName.toString())
      );






      share|improve this answer

























        1












        1








        1







        Try with map



        getActiveProgramNames(): Observable<string[]> 
        return this.getActivePrograms()
        .pipe(
        map(data => data.map(program => program.ProgramName.toString())
        );






        share|improve this answer













        Try with map



        getActiveProgramNames(): Observable<string[]> 
        return this.getActivePrograms()
        .pipe(
        map(data => data.map(program => program.ProgramName.toString())
        );







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 20:51









        Derviş KayımbaşıoğluDerviş Kayımbaşıoğlu

        16.1k22142




        16.1k22142





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328378%2ftype-program-is-not-assignable-to-string%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript