#My type checker doesn't inherit types from interface, but checks for them
27 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
functional code: ```ts
export class OptionManager implements OptionManagerInterface {
private builder: PrefixBuilder;
args: string[];
constructor(args: string[], builder: PrefixBuilder) {
this.builder = builder;
this.args = args;
}
get(name, required) {
var indice: number | null = null;
for (let index = 0; index < this.builder.args.length; index++) {
const arg = this.builder.args[index]
if (arg.name == name) {
indice = index;
}
}
if (!indice) {
throw new Error(`Name ${name} not recognized.`)
}
if (indice || required) {
return this.args[indice];
}
return null;
}
}
Because that's how it behaves, you need to copy the overloads above the function as well, because it checks implementation signatures against all overloads.
Also there is a findIndex option to search for indexes
why would i seperate my typing to remove the clutter only to have to add the clutter there anyway
i remember this one repo did this
I mean when using the function in actual codebase
const xyz: someinterface = new Xyz()
xyz.get()``` you will get the intellisense, it's just so after you could those inside the class itself and without specifically attaching a type to it later
please add the verb after could
class XyzInterface {
xyz(name: string, required: false): string | null;
xyz(name: string, required: true): string;
}
class Xyz implements XyzInterface {
xyz(name: string, required: false): string | null;
xyz(name: string, required: true): string;
xyz(name: string, required: boolean): string | null {
}
}
``` If you implement overloads in the class, you dont need to attach types later to it, otherwise when initializing the class
```ts
const xyz: XyzInterface = new Xyz()
xyz.xyz()``` you can attach the type and intellisense will work
what?
the interface is literally useless
also implementation files .ts dont allow overloads im pretty sure
what the fuck is this language
i hate this
jdphpfoiuhdsopfhsdopfhpsdhfidfosdhidhfosifheofohfhoehof
what the fuck this exists now??
also why are theres 25 ^ 10 files for each fucking type
i hate this so much
fuck this
It does
*they do
Thank you for the correction, I hope and believe it will fix your issues
did that one use interface merging (name the interface the same as the class) maybe?
they didnt
Link to the repo then and we can help you how to achieve what they did
also that implementation code is wrong, it throws if the indice is the first (0)
and you don't want to search in the entire array after you've already found it