[Typescript] Utilise Typescript object spread vs custom extendObj method
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...
@damienpontifex I definitely welcome enhancements to leverage new features in a programming language.
Your suggestion is related to https://github.com/swagger-api/swagger-codegen/issues/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?
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
@damienpontifex OK. Please kindly submit a PR so that we can review the enhancement.
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);
@todrules I also like backward compatible solution so may I know if you've time to submit a PR with your enhancement?
@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.
@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.
I'll make the modifications and downgrade the sample ts versions to align with the suggestion by @todrules
@todrules the PR by @damienpontifex has been merged into master. Please pull the latest master to give it a try.