0
 static fromDto(httpClient: HttpClient, adalSvc: MsAdalAngular6Service) {
        return (dto: Dto) => {
          return new Note(httpClient, dto.xxx, adalSvc);

        };
   }

How to get the Note object from this static method in typescript. I have create a Dto object and trying to pass it to this method which will give me a Note object but can't seem to do that.

What I did was this

const notes = dtos.map(d => {
Note.fromDto(null, null).apply(d); });

can you please tell me how to do that?

1 Answer 1

1

Your fromDto returns a function whose signature matches what the map array function callback. At the moment your map callback is returning nothing, so will produce an array of undefined values.

You can use the long version and return from the callback:

const notes = dtos.map(d => {
  return Note.fromDto(null, null)(d); 
});

Or the slightly shorter version with a single-line body:

const notes = dtos.map(d => Note.fromDto(null, null)(d));

Or you can pass the function in as the callback:

const notes = dtos.map(Note.fromDto(null, null));

DEMO: https://stackblitz.com/edit/angular-nsdpcr

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.