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

[TypeScript] Can't use string, array or object as value in shape generator #93

Open
sesm opened this issue Jun 12, 2018 · 2 comments
Open

Comments

@sesm
Copy link

sesm commented Jun 12, 2018

Documentation shows the following example for shape generator:

gen({
  type: 'Place',
  name: gen.string,
  location: [ gen.number, gen.number ],
  address: {
    street: gen.string,
    city: gen.string
  }
})

This works perfectly fine in plain JS in master.

But in TS:

gen({
  type: 'Place'
})

causes compilation error: Type 'string' is not assignable to type 'ValueGenerator<{}>'

gen({
  location: [ gen.number, gen.number ],
})

causes compilation error: Type 'ValueGenerator<number>[]' is not assignable to type 'ValueGenerator<{}>'.

gen({
  address: {
    street: gen.string,
    city: gen.string
  }
})

causes compilation error: Type '{ street: ValueGenerator<string>; city: ValueGenerator<string>; }' is not assignable to type 'ValueGenerator<{}>'.

@sesm
Copy link
Author

sesm commented Jun 12, 2018

This looks like a more specific case of #79

@sesm
Copy link
Author

sesm commented Jun 13, 2018

Found an easy workaround:

gen({
  type: 'Place',
  name: gen.string,
  location: [ gen.number, gen.number ],
  address: {
    street: gen.string,
    city: gen.string
  }
} as {})

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

No branches or pull requests

1 participant