Git Product home page Git Product logo

Comments (3)

devniel avatar devniel commented on September 28, 2024 1

hello, same problem here 😑;
UPDATED: solved when adding the await.

from oclif.github.io.

seiltingcr avatar seiltingcr commented on September 28, 2024

There is more; the example code does not compile at all. Even ignoring the implicit 'any' errors that come up in the default configuration generated by oclif, there is this:

src/base/command.ts:20:32 - error TS2559: Type 'Function' has no properties in common with type 'Input<any>'.

20     const {flags} = this.parse(this.constructor)

This works well in plain JS (just like MyCommand.flags vs this.flags), but typescript basically does not seem to allow calling this.parse from a base class and having it do the right thing in derived classes...

from oclif.github.io.

paulxtiseo avatar paulxtiseo commented on September 28, 2024

I'm wondering the same thing with a project I just started. Wondering if this is resolved? It would seem the docs are outdated relative to the actual project.

Errors:

src/configured-command.ts:13:12 - error TS2339: Property 'flags' does not exist on type 'Promise<ParserOutput<unknown, { [name: string]: any; }>>'.

13     const {flags} = this.parse(this.constructor)
              ~~~~~

src/configured-command.ts:13:32 - error TS2559: Type 'Function' has no properties in common with type 'Input<unknown>'.

13     const {flags} = this.parse(this.constructor)
                                  ~~~~~~~~~~~~~~~~

src/commands/config/create.ts:24:44 - error TS2304: Cannot find name 'Deploy'.

24     const {args, flags} = await this.parse(Deploy)
                                              ~~~~~~

src/commands/deploy/index.ts:4:22 - error TS2417: Class static side 'typeof Deploy' incorrectly extends base class static side 'typeof default'.
  Types of property 'flags' are incompatible.
    Property 'config' is missing in type '{ all: BooleanFlag<boolean>; num: OptionFlag<number | undefined>; }' but required in type '{ config: BooleanFlag<boolean>; }'.

4 export default class Deploy extends Command {
                       ~~~~~~

  src/configured-command.ts:5:5
    5     config: Flags.boolean({
          ~~~~~~~~~~~~~~~~~~~~~~~
    6       char: 'c',
      ~~~~~~~~~~~~~~~~
    7       description: '',
      ~~~~~~~~~~~~~~~~~~~~~~
    8     }),
      ~~~~~~
    'config' is declared here.

configured-command.ts

import {Command, Flags} from '@oclif/core'

export default abstract class extends Command {
  static flags = {
    config: Flags.boolean({
      char: 'c',
      description: 'Path to config file',
    }),
  }

  async init(): Promise<void> {
    // do some initialization
    const {flags} = this.parse(this.constructor)
    console.log('config', flags)
  }
}

deploy/index.ts

import {Flags} from '@oclif/core'
import Command from '../../configured-command'

export default class Deploy extends Command {
  static summary = 'Deploy new migrations up to the target database.'
  static description = 'This command will deploy (a.k.a. push, execute) one or more migrations against a specific target. The command will not execute migrations that have already been executed against the target.'
  static examples = ['$ loco deploy']

  static flags = {
    all: Flags.boolean({
      char: 'a',
      description: 'Deploy all undeployed migrations in the target migration source folder (declared in the configuration).',
      exclusive: ['num'],
    }),
    num: Flags.integer({
      char: 'n',
      description: 'Deploy a number of undeployed migrations in the target migration source folder (declared in the configuration). The migrations will be sorted lexicographically before counting them.',
      exclusive: ['all'],
    }),
  }

  static args = [{name: 'target', description: 'The target to deploy against, as indicated by the name (or one of the aliases) in the config data. To hit all configured targets, use "*".', required: true}]

  async run(): Promise<void> {
    const {args, flags} = await this.parse(Deploy)
    console.log('deploy args', args)
    console.log('deploy flags', flags)
  }
}

from oclif.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.