Uncertain whether it's a typescript bug or an error in my code. I've been working on a plugin that generates code, but upon generation, I encounter the issue
This overload signature is not compatible with its implementation signature
in the resulting file.
A simple reproducible example is provided below. It seems like the error surfaces when any variable is added to one of the extending classes. In this scenario, removing protected anything = 'test';
eliminates the error.
abstract class GraphtonBaseReturnTypeBuilder {
public withRelated(relatedType: string, buildFields: (r: GraphtonBaseReturnTypeBuilder) => void): this {
return this;
}
}
type UserReturnTypeObjectField = "posts"|"friends";
class UserReturnTypeBuilder extends GraphtonBaseReturnTypeBuilder {
protected anything = 'test';
public withRelated(relatedType: "posts", buildFields: (r: PostReturnTypeBuilder) => void): this;
// ~~~~~~~~~~~ This overload signature is not compatible with its implementation signature
public withRelated(relatedType: "friends", buildFields: (r: UserReturnTypeBuilder) => void): this;
public withRelated(relatedType: UserReturnTypeObjectField, buildFields: (r: GraphtonBaseReturnTypeBuilder) => void): this {
return super.withRelated(relatedType, buildFields);
}
}
type PostReturnTypeObjectField = "author"|"repatedPosts";
class PostReturnTypeBuilder extends GraphtonBaseReturnTypeBuilder {
public withRelated(relatedType: "author", buildFields: (r: UserReturnTypeBuilder) => void): this;
// ~~~~~~~~~~~ This overload signature is not compatible with its implementation signature
public withRelated(relatedType: "repatedPosts", buildFields: (r: PostReturnTypeBuilder) => void): this;
public withRelated(relatedType: PostReturnTypeObjectField, buildFields: (r: GraphtonBaseReturnTypeBuilder) => void): this {
return super.withRelated(relatedType, buildFields);
}
}
The complete file can be found on github: https://github.com/GraphtonLib/Graphton/blob/main/example/graphton.generated.ts
The problematic lines are located at line 229 and line 259
Full error details:
example/graphton.generated.ts:229:12 - error TS2394: This overload signature is not compatible with its implementation signature.
public withRelated(relatedType: "posts", buildFields: (r: PostReturnTypeBuilder) => void): this;
~~~~~~~~~~~
example/graphton.generated.ts:231:12
231 public withRelated(relatedType: UserReturnTypeObjectField, buildFields: (r: GraphtonBaseReturnTypeBuilder) => void): this {
~~~~~~~~~~~
The implementation signature is declared here.
example/graphton.generated.ts:259:12 - error TS2394: This overload signature is not compatible with its implementation signature.
259 public withRelated(relatedType: "author", buildFields: (r: UserReturnTypeBuilder) => void): this;
~~~~~~~~~~~
example/graphton.generated.ts:261:12
261 public withRelated(relatedType: PostReturnTypeObjectField, buildFields: (r: GraphtonBaseReturnTypeBuilder) => void): this {
~~~~~~~~~~~
The implementation signature is declared here.