Skip to content

Commit 57b073a

Browse files
authored
Add void returns to constructors (#863)
Fixes #857 This fixes an issue where flow implicitly types new Class as `any` if the constructor is not typed to return `void` (facebook/flow#2748).
1 parent c493b06 commit 57b073a

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

src/language/source.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Source {
1818
body: string;
1919
name: string;
2020

21-
constructor(body: string, name?: string) {
21+
constructor(body: string, name?: string): void {
2222
this.body = body;
2323
this.name = name || 'GraphQL';
2424
}

src/type/definition.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class GraphQLScalarType {
297297

298298
_scalarConfig: GraphQLScalarTypeConfig<*, *>;
299299

300-
constructor(config: GraphQLScalarTypeConfig<*, *>) {
300+
constructor(config: GraphQLScalarTypeConfig<*, *>): void {
301301
assertValidName(config.name);
302302
this.name = config.name;
303303
this.description = config.description;
@@ -417,7 +417,7 @@ export class GraphQLObjectType {
417417
_fields: GraphQLFieldMap<*, *>;
418418
_interfaces: Array<GraphQLInterfaceType>;
419419

420-
constructor(config: GraphQLObjectTypeConfig<*, *>) {
420+
constructor(config: GraphQLObjectTypeConfig<*, *>): void {
421421
assertValidName(config.name, config.isIntrospection);
422422
this.name = config.name;
423423
this.description = config.description;
@@ -696,7 +696,7 @@ export class GraphQLInterfaceType {
696696
_typeConfig: GraphQLInterfaceTypeConfig<*, *>;
697697
_fields: GraphQLFieldMap<*, *>;
698698

699-
constructor(config: GraphQLInterfaceTypeConfig<*, *>) {
699+
constructor(config: GraphQLInterfaceTypeConfig<*, *>): void {
700700
assertValidName(config.name);
701701
this.name = config.name;
702702
this.description = config.description;
@@ -774,7 +774,7 @@ export class GraphQLUnionType {
774774
_types: Array<GraphQLObjectType>;
775775
_possibleTypeNames: {[typeName: string]: boolean};
776776

777-
constructor(config: GraphQLUnionTypeConfig<*, *>) {
777+
constructor(config: GraphQLUnionTypeConfig<*, *>): void {
778778
assertValidName(config.name);
779779
this.name = config.name;
780780
this.description = config.description;
@@ -888,7 +888,7 @@ export class GraphQLEnumType/* <T> */ {
888888
_valueLookup: Map<any/* T */, GraphQLEnumValue>;
889889
_nameLookup: { [valueName: string]: GraphQLEnumValue };
890890

891-
constructor(config: GraphQLEnumTypeConfig/* <T> */) {
891+
constructor(config: GraphQLEnumTypeConfig/* <T> */): void {
892892
this.name = config.name;
893893
assertValidName(config.name, config.isIntrospection);
894894
this.description = config.description;
@@ -1067,7 +1067,7 @@ export class GraphQLInputObjectType {
10671067
_typeConfig: GraphQLInputObjectTypeConfig;
10681068
_fields: GraphQLInputFieldMap;
10691069

1070-
constructor(config: GraphQLInputObjectTypeConfig) {
1070+
constructor(config: GraphQLInputObjectTypeConfig): void {
10711071
assertValidName(config.name);
10721072
this.name = config.name;
10731073
this.description = config.description;
@@ -1176,7 +1176,7 @@ export type GraphQLInputFieldMap = {
11761176
export class GraphQLList<T: GraphQLType> {
11771177
ofType: T;
11781178

1179-
constructor(type: T) {
1179+
constructor(type: T): void {
11801180
invariant(
11811181
isType(type),
11821182
`Can only create List of a GraphQLType but got: ${String(type)}.`
@@ -1221,7 +1221,7 @@ GraphQLList.prototype.toJSON =
12211221
export class GraphQLNonNull<T: GraphQLNullableType> {
12221222
ofType: T;
12231223

1224-
constructor(type: T) {
1224+
constructor(type: T): void {
12251225
invariant(
12261226
isType(type) && !(type instanceof GraphQLNonNull),
12271227
'Can only create NonNull of a Nullable GraphQLType but got: ' +

src/type/directives.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class GraphQLDirective {
5353
locations: Array<DirectiveLocationEnum>;
5454
args: Array<GraphQLArgument>;
5555

56-
constructor(config: GraphQLDirectiveConfig) {
56+
constructor(config: GraphQLDirectiveConfig): void {
5757
invariant(config.name, 'Directive must be named.');
5858
assertValidName(config.name);
5959
invariant(

src/type/schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class GraphQLSchema {
6565
[abstractName: string]: { [possibleName: string]: boolean }
6666
};
6767

68-
constructor(config: GraphQLSchemaConfig) {
68+
constructor(config: GraphQLSchemaConfig): void {
6969
invariant(
7070
typeof config === 'object',
7171
'Must provide configuration object.'

src/utilities/TypeInfo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class TypeInfo {
6464
// to support non-spec-compliant codebases. You should never need to use it.
6565
// It may disappear in the future.
6666
getFieldDefFn?: typeof getFieldDef
67-
) {
67+
): void {
6868
this._schema = schema;
6969
this._typeStack = [];
7070
this._parentTypeStack = [];

src/utilities/extendSchema.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@ export function extendSchema(
441441

442442
function extendFieldType<T: GraphQLType>(typeDef: T): T {
443443
if (typeDef instanceof GraphQLList) {
444-
return new GraphQLList(extendFieldType(typeDef.ofType));
444+
return (new GraphQLList(extendFieldType(typeDef.ofType)): any);
445445
}
446446
if (typeDef instanceof GraphQLNonNull) {
447-
return new GraphQLNonNull(extendFieldType(typeDef.ofType));
447+
return (new GraphQLNonNull(extendFieldType(typeDef.ofType)): any);
448448
}
449449
return getTypeFromDef(typeDef);
450450
}

src/validation/rules/OverlappingFieldsCanBeMerged.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ function subfieldConflicts(
776776
class PairSet {
777777
_data: {[a: string]: {[b: string]: boolean}};
778778

779-
constructor() {
779+
constructor(): void {
780780
this._data = Object.create(null);
781781
}
782782

src/validation/validate.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ export class ValidationContext {
111111
_variableUsages: Map<NodeWithSelectionSet, Array<VariableUsage>>;
112112
_recursiveVariableUsages: Map<OperationDefinitionNode, Array<VariableUsage>>;
113113

114-
constructor(schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo) {
114+
constructor(
115+
schema: GraphQLSchema,
116+
ast: DocumentNode,
117+
typeInfo: TypeInfo
118+
): void {
115119
this._schema = schema;
116120
this._ast = ast;
117121
this._typeInfo = typeInfo;

0 commit comments

Comments
 (0)