I need to translate these Java constructor overloads to Typescript:
public QueryMixin() {
this(null, new DefaultQueryMetadata(), true);
}
public QueryMixin(QueryMetadata metadata) {
this(null, metadata, true);
}
public QueryMixin(QueryMetadata metadata, boolean expandAnyPaths) {
this(null, metadata, expandAnyPaths);
}
public QueryMixin(T self) {
this(self, new DefaultQueryMetadata(), true);
}
public QueryMixin(T self, QueryMetadata metadata) {
this(self, metadata, true);
}
public QueryMixin(T self, QueryMetadata metadata, boolean expandAnyPaths) {//...}
I've tried create these constructors taking a look over there, but I've not been able to figure out how to get it...
Any ideas?
constructor(); <<<1>>>
constructor(metadata: QueryMetadata);
constructor(metadata: QueryMetadata, expandAnyPaths: boolean);
constructor(self: T);
constructor(self: T, metadata: QueryMetadata);
constructor(selfOrMetadata: T | QueryMetadata, expandAnyPaths: boolean) {
this.self = selfOrMetadata; <<< PROBLEM HERE
this.metadata = selfOrMetadata; <<< PROBLEM HERE
this.expandAnyPaths = expandAnyPaths;
}
On <<<1>>> I'm getting this compilation message:
Overload signature is not compatible with function implementation.
constructor(selfOrMetaData?: T | QueryMetadata ...)and so on. Alternatively you can just drop the pretense of having any type safety at that point and just doconstructor(,,,args: any[]).selfOrMetadatai assignable toselformetadata.selfOrMetaData?), since there's at least one overload where neither argument is supplied. Also, your second argument similarly needs to be a union of all possible argument types in the second position.expandAnyPathsOrMetadata?: boolean | QueryMetadata.