1

I'am have:

interface Intfff
{
     csv: {
       (url: string);
       parsess(lol: string);      
   };
}

class Class implements Intfff
{
    csv(url: string) {

    }
}

var obj: Intfff = new Class();
obj.csv('sdfsdf');
obj.csv.parsess('sdf');

How do I implement a method csv.parsess() ? translator typeScript an error on Class: missing property 'parsess' from type ...

Help me understand

2 Answers 2

2

Why not try this instead?

interface Intfff
{
    csv(url: string): Intfff;
    parsess(lol:string):string;
}

class TestClass implements Intfff
{
    csv(url: string) {  
        return this;
    }
    parsess(lol: string) {
        return "Hello";
    }
}

var obj: Intfff = new TestClass();
obj.csv('sdfsdf').parsess('sdf');
Sign up to request clarification or add additional context in comments.

1 Comment

"obj.csv('sdfsdf').parsess('sdf');" is invalid expression. Should be: obj.csv.parsess('sdf') // valid obj.csv('str') // valid
2

You can't fullfill that interface with a class method. You will have to define the function as type any, and add the missing member, before adding it to the object.

interface Intfff
{
    csv: {
        (url: string);
        parsess(lol: string);      
    };
}

class Test implements Intfff {
    public csv : { (url: string); parsess(lol: string); };

    constructor() {
        var csv : any = function (url: string) {
            // ...
        };
        csv.parsess = function (lol: string) {
            // ...
        };
        this.csv = csv;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.