#TypeScript with Yargs

1 messages · Page 1 of 1 (latest)

azure eagle
#

Hi, I've got a yargs TS code, like:

let argv = hideBin(process.argv)
let optParser = yargs(argv)
    .scriptName('')
    .usage(usage)
    .epilogue(epilogue)
    .help()
    .version(false)
    .parserConfiguration({ 'populate--': true })
    .strict()
    .options({
        port: {
            group: configOptionsGroup,
            describe: `Port to use [${Server.DEFAULT_PORT}]`,
            type: 'string',
        },
        project: {
            group: configOptionsGroup,
            describe: 'Open the specified project on startup',
            type: 'string',
        }, 
        ... // many more
    )
let args = optParser.parse()
let foo = args.port

And TS tells me that port does not exist there, although it shows that it exists in the type:

Property 'port' does not exist on type '{ [x: string]: unknown; port: string; project: string; server: boolean; window: boolean; "background-throttling": boolean; backgroundThrottling: boolean; backend: boolean; "backend-path": unknown; backendPath: unknown; ... 30 more ...; $0: string; } | Promise<...>'.
  Property 'port' does not exist on type 'Promise<{ [x: string]: unknown; port: string; project: string; server: boolean; window: boolean; "background-throttling": boolean; backgroundThrottling: boolean; backend: boolean; "backend-path": unknown; backendPath: unknown; ... 30 more ...; $0: string; }>'.

227 let foo = args.port

I see it in the type, would anyone be so nice and tell me what I'm missing here, please? 🙂

#

hmm, I'll try setting the options that are provided there. Its strange it does fail with such a misleading error though

#

Indeed, when using const yargs = require('yargs') instead of import yargs from 'yargs' it works fine!

native jasper
#

Indeed, when using const yargs = require('yargs') instead of import yargs from 'yargs' it works fine!
@azure eagle Generally when you use require that just means the package is coming in as any.