Giter Club home page Giter Club logo

Comments (14)

PatrykWalach avatar PatrykWalach commented on April 28, 2024
  1. If you don't need typescript types
export default createComponent({
  setup(props) {
    return {}
  },
  props: {
    simple: {
      type: String,
      required: true
    },
  } as const
})

interface Props {
  simple: string
}
  1. If you need typescript types
export default createComponent({
  setup(props) {
    return {}
  },
  props: ({
    advanced: {
      required: true
    },
  } as unknown) as Props
})

interface Props {
  advanced: {
    a: string
    b: number
  }
}

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

THX very much

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

I still got error:

Conversion of type '{ readonly list: ArrayConstructor; }' to type 'Props' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Types of property 'list' are incompatible.
    Type 'ArrayConstructor' is missing the following properties from type 'GridMenuList[]': pop, push, concat, join, and 27 more.Vetur(2352)
Conversion of type '{ readonly list: ArrayConstructor; }' to type 'Props' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Types of property 'list' are incompatible.
    Type 'ArrayConstructor' is not comparable to type 'GridMenuList[]'.

when

interface Props {
  list: GridMenuList[]
}

const DropdownGrid = createComponent({
  props: ({
    list: Array
  } as const) as Props,
  setup(props) {
  ...

So maybe I still need to convert to unknown first?

from composition-api.

PatrykWalach avatar PatrykWalach commented on April 28, 2024

There was an error in my example, I've fixed it.

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

I got error when

  • as unknown as Props as const
  • as unknown as const as Props

and no const effect when as const as unknown as Props

So how should I do?

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

Oh thx, so when I want types I can not convert to const, is that right?

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

By the way, I don't think we need that parentheses(I am not sure whether I spell right). It seems ok when I remove it.

from composition-api.

PatrykWalach avatar PatrykWalach commented on April 28, 2024

I don't use as const with interface Props If you want to be sure to not assign to props I think you can do as unknown as Readonly<Props>

from composition-api.

PatrykWalach avatar PatrykWalach commented on April 28, 2024

My linter adds parenthesis but It's not required

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

@GODOFHOPE Try v2.2.0.

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

🆗,I'll try ^-^

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

Excuse me ,waht's impoving? I cannot feel any enhancement. Could you tell me more specificitly?
I stitll catch error whtn writing originally, yet I still needs to convert to unknown.

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

I noticed the provide/inject types improve, by checking your commits and I alse noticed an enhancement with states, but none about props.

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

@GODOFHOPE Can you show me your codes? An online example would be great.

from composition-api.

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.