Typing array elements
laurensdijkstra opened this issue · 3 comments
laurensdijkstra commented
In the Readme.MD you wrote Note: Currently creating type from array element is not supported in TypeScript. See https://github.com/Microsoft/TypeScript/issues/28046
In that issue thread someone seems to have posted a solution that works with TS > 3.4. Does this help typed-graphqlify?
acro5piano commented
Thanks! I'll check it later.
acro5piano commented
Very slow response, but I've finally checked it.
import { query, types } from 'typed-graphqlify'
const UserType = ['Student', 'Teacher',] as const
query('getUser', {
user: {
id: types.number,
name: types.string,
type: types.oneOf(UserType),
},
})
We may also support TS < 3.4 with overload signature.
And this utility-type do the same thing:
https://github.com/piotrwitek/utility-types#elementtypet-k
acro5piano commented
@laurensdijkstra
I've add the feature in the following PR. Thanks!
#68