Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript] Utilise Typescript object spread vs custom extendObj method #4407

Closed
damienpontifex opened this issue Dec 16, 2016 · 9 comments
Closed

Comments

@damienpontifex
Copy link
Contributor

Description

Typescript 2.1 allows object spread (see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#object-spread-and-rest). The Typescript templates currently define an extendObj method to achieve this same feature e.g. https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache#L44-L51

Swagger-codegen version

2.2.1

Suggest a Fix

Remove extendObj in api.mustache files and just utilise object rest operator.

I can provide a fix with a PR unless there's any reason not to...

@wing328
Copy link
Contributor

wing328 commented Dec 16, 2016

@damienpontifex I definitely welcome enhancements to leverage new features in a programming language.

Your suggestion is related to #4375

Is my understanding correct that there's no way to make this particular change so that the output is compatible with both 2.1.4 and 2.1.1?

@damienpontifex
Copy link
Contributor Author

Yes, my solution would resolve that issue in my preliminary testing.

I thought the feature was available in typescript 2.1.x, but looking at this issue on the Typescript repo, it has a milestone of 2.1.4 so maybe it was only finally included with the minor 2.1 release

@wing328
Copy link
Contributor

wing328 commented Dec 16, 2016

@damienpontifex OK. Please kindly submit a PR so that we can review the enhancement.

@todrules
Copy link

Locally, I'm using Object.assign to fix this issue, and it's working so far - at least it's adding my extra request params. Object.assign should be backwards compatible, too, so I thought I'd throw this out there. Here's the solution:

requestOptions = Object.assign(requestOptions, extraHttpRequestParams);

@wing328
Copy link
Contributor

wing328 commented Jan 3, 2017

@todrules I also like backward compatible solution so may I know if you've time to submit a PR with your enhancement?

@damienpontifex
Copy link
Contributor Author

@wing328 you mentioned in #4409 about changing that PR to v2.3. Would we do a backwards compatible change in 2.2 and then the spread operator in 2.3? If both achieve the same thing, would a second change in 2.3 that isn't backwards compatible add any value?

Just wondering if we abandon the spread operator change and just adopt Object.assign as @todrules suggested. This would also remove the changes to use @types for typing definitions in the samples.

@wing328
Copy link
Contributor

wing328 commented Jan 9, 2017

@damienpontifex both your approach and the approach suggested by @todrules are ok with me. Personally I prefer 1 solution without introducing breaking changes (which require TS version upgrade) if possible.

@damienpontifex
Copy link
Contributor Author

I'll make the modifications and downgrade the sample ts versions to align with the suggestion by @todrules

@wing328
Copy link
Contributor

wing328 commented Jan 17, 2017

@todrules the PR by @damienpontifex has been merged into master. Please pull the latest master to give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants