babel icon indicating copy to clipboard operation
babel copied to clipboard

feature: TSTypeOperator: keyof (#16799)

Open coderaiser opened this issue 1 year ago • 2 comments

Q                       A
Fixed Issues? Fixes https://github.com/babel/babel/issues/16799
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

coderaiser avatar Dec 05 '24 20:12 coderaiser

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/59636

babel-bot avatar Dec 05 '24 20:12 babel-bot

Since a TSTypeOperator without operator is not valid, maybe we can not treat it as a new feature?

liuxingbaoyu avatar Dec 06 '24 17:12 liuxingbaoyu

Since a TSTypeOperator without operator is not valid, maybe we can not treat it as a new feature?

OK, will merge it as a bugfix once CI passes.

JLHwung avatar Jun 26 '25 13:06 JLHwung

hi, I have a question about this change.

It seems to make the second argument of TSTypeOperator mandatory, which would be a breaking change for those relying on the previous behavior. Previously, this argument was not required. Could you confirm if this is intentional?

trfv avatar Jul 18 '25 02:07 trfv

It was a bug, operator cannot be empty it produces invalid code.

coderaiser avatar Jul 18 '25 07:07 coderaiser

Yeah the difference was that before we would let you create an invalid AST and then silently print some code that does not correspond to it. Now we prevent you from generating the invalid AST in the first place.

nicolo-ribaudo avatar Jul 18 '25 08:07 nicolo-ribaudo

@coderaiser @nicolo-ribaudo

Thank you for the clarification.

I understand this is intended as a bug fix, but it seems to be a breaking change. Shouldn't we consider including it in a major release to align with semantic versioning?

Also, for existing babel plugins that used TSTypeOperator without the second argument, is the recommended path for them to update their own code? I'd like to understand the intended migration path for users.

trfv avatar Jul 18 '25 12:07 trfv

Mh yeah I saw your code, and indeed it was not "generating invalid Babel output". I'll open a PR to make this parameter optional in Babel 7.

nicolo-ribaudo avatar Jul 18 '25 12:07 nicolo-ribaudo