testcheck-js
testcheck-js copied to clipboard
[TypeScript] Can't use string, array or object as value in shape generator
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<{}>'.
This looks like a more specific case of #79
Found an easy workaround:
gen({
type: 'Place',
name: gen.string,
location: [ gen.number, gen.number ],
address: {
street: gen.string,
city: gen.string
}
} as {})