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

Cannot define custom args due to missing ArgDefinition export #1136

Closed
mat-if opened this issue Jul 9, 2024 · 0 comments · Fixed by #1137
Closed

Cannot define custom args due to missing ArgDefinition export #1136

mat-if opened this issue Jul 9, 2024 · 0 comments · Fixed by #1137

Comments

@mat-if
Copy link

mat-if commented Jul 9, 2024

Describe the bug

A custom re-usable Arg created in @oclif/core 3.27.0 is throwing an error when trying to upgrade to @oclif/core 4.0.9:

error TS2742: The inferred type of 'UrlArg' cannot be named without a reference to '../../node_modules/@oclif/core/lib/interfaces/parser'. This is likely not portable. A type annotation is necessary.

The Arg in question reports a type of ArgDefinition<Url, Record<string, unknown>>

Upon investigation, it appears that exporting ArgDefinition in https://github.com/oclif/core/blob/main/src/interfaces/index.ts fixes the issue, although it's not clear to me if there is a more correct way to do this.

It's also unclear as to why this started happening in 4.x since it doesn't appear there were any major changes to either interfaces/index.ts or interfaces/parser.ts

To Reproduce
Steps to reproduce the behavior:

Create a custom arg:

import { Args } from '@oclif/core'

type Url = {
  protocol: string | null
  hostname: string
  port: number | null
}

// Simplified for demonstration purposes
export function parseUrl(_input: string): Promise<Url> {
  return Promise.resolve({
    protocol: null,
    hostname: 'google.com',
    port: null,
  })
}

export const UrlArg = Args.custom<Url>({
  parse: async (input: string) => parseUrl(input),
})

Expected behavior

Typescript code compiles and arg is usable

Screenshots
image

Environment (please complete the following information):

  • OS & version: MacOS Monterey 12.6.3
  • Shell/terminal & version:
    • Shell: fish, version 3.7.0
    • Terminal: Ghostty , version 31d53849

Additional context
Add any other context about the problem here.

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

Successfully merging a pull request may close this issue.

1 participant