Skip to content

Parens on union type fail for function arguments (JSDoc style) #25779

Closed
@tschaub

Description

@tschaub

TypeScript Version: [email protected]

Search Terms: function arguments grouped union type

Code

I notice that if a union type is grouped with ( and ) it works as a return type but not as an argument type. For example, this does not work:

/**
 * @typedef {function((string|undefined)): (string|undefined)} SomeType
 */

While this does work:

/**
 * @typedef {function(string|undefined): (string|undefined)} SomeType
 */

Expected behavior:

With this tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2017",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "strict": false,
  },
  "include": [
    "src/**/*.js"
  ]
}

I expected tsc to succeed.

Actual behavior:


src/main.js:2:23 - error TS1138: Parameter declaration expected.

2  * @typedef {function((string|undefined)): (string|undefined)} SomeType
                        ~

src/main.js:2:41 - error TS1005: '}' expected.

2  * @typedef {function((string|undefined)): (string|undefined)} SomeType
                                          ~

Perhaps this is a known limitation. I can remove the parens. But I thought it might also be a parsing bug.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationFixedA PR has been merged for this issuecheckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions