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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현