-
Notifications
You must be signed in to change notification settings - Fork 2k
[flow] Add generics for scalar class #1487
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
[flow] Add generics for scalar class #1487
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@Slessi can you check this as well gtkatakura/fullstack-challenge@36cc105 export const GraphQLInt: GraphQLScalarType<number>;
export const GraphQLFloat: GraphQLScalarType<number>;
export const GraphQLString: GraphQLScalarType<string>;
export const GraphQLBoolean: GraphQLScalarType<boolean>;
export const GraphQLID: GraphQLScalarType<string>; following this approach we could use mapped types in Typescript to transform GraphQLInt to |
@sibelius I don't understand what you are trying to tell me. I made a PR to |
you PR does not add correct types for GraphQLInt for instance |
Yes but what difference does that make in practice? If you're making a custom scalar resolver, you can just make a new type, i.e. const ID = new GraphQLScalarType<number, string>({
name: "ID",
description: "ID Object",
serialize: (value) => String(value),
parseValue,
parseLiteral: (valueNode, variables) => {
if (valueNode.kind !== "StringValue") {
throw new Error("Expected StringValue");
}
return parseValue(valueNode.value);
},
}); |
you can use Mapped Types on Typescript to transform |
tests still failing I think in flow default of generics is different <TInternal: any> or you should try <TInternal?: any> try running flow check locally to make it typecheck properly |
@sibelius I don't know how to fix it, as mentioned in OP. If you want to try yourself, feel free |
@gtkatakura-bysoft thanks for that, going to close this then as its far too trivial an improvement to merit a breaking change like that. Unfortunate however that the maintainers of |
Basically I want to add the option to specify generics on
GraphQLScalarType
, and not justGraphQLScalarTypeConfig
Not sure how to resolve the following issue in flow though
I would not want to create a change that forces users to add
<>
to their code - Is there a way in flow to make the generics totally optional as in TypeScript?