acro5piano/typed-graphqlify

Typing array elements

laurensdijkstra opened this issue · 3 comments

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?

microsoft/TypeScript#28046 (comment)

Thanks! I'll check it later.

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

@laurensdijkstra
I've add the feature in the following PR. Thanks!
#68