-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
💻
- Would you like to work on a fix?
How are you using Babel?
babel-loader (webpack)
Input code
type FuncWithDescription = [
function: (...args: any[]) => any,
string: string
]
Configuration file name
No response
Configuration
See REPL link
Current and expected behavior
Current
It throws at line 2: /repl.tsx: Unexpected token (2:2)
If you rename function to fn, then
it throws at line 3: Tuple members must be labeled with a simple identifier. (3:2)
Expected
It does not throw an error on either line. Why would I expect this? Because TS is totally fine with this same code: https://www.typescriptlang.org/play?ts=4.0.2#code/C4TwDgpgBAYgrgOwMYHUCWwAWARCBnJAJzTGDQHsEoBeKAbQFgAoKVqAM0STMoC4oAFADoRAQ0IBzPP1EIQdALoBKagD4oskABpmbKHmDEEE-gaMTmC5sySUDHBOiy4CxUhQTTYXJznxESHgRFGnpdNjoBAA9eBDgAWwAjCEIlGnUorSgAIkIIYDhCKixoOKSU7IUdFgjo2ITkwiyQevLU9KgogCptHPi4ABsyMAGQKBKoMsa8SssgA
Environment
See REPL link for env details
Possible solution
There are two ways to fix this problem, in my opinion
Option 1: Updated docs, and better error messages
Indicate in the docs (just like with other caveats) that there are certain tokens that are not acceptable for named tuple positions.
Then, ensure that the errors thrown in my example above clearly state this problem and/or reference the newly updated docs. I think the second error (Tuple members must be labeled with a simple identifier.) is possibly acknowledging this discrepancy, but it is not clear to me that the error is a known caveat vs an actual TS syntax issue. (The first error thrown against the word function, though, is quite vague.)
Option 2: Update the TypeScript plugin to handle these names
I do not know how many words fail in the Babel plugin, and yet succeed in TS. I do know that the following are in the list:
functionstringnumber
Additional context
No response