A
A
Alexey2017-08-10 14:23:13
typescript
Alexey, 2017-08-10 14:23:13

Declaration of variables and properties, types in Typescript. What is the correct approach?

Actually the situation is this:
There is a code:

export default class Cookies {
    public type: string;
    public model: string;
    public status: string;

    getStatus(t: string) : string {
        console.log(t + ' : ' + this.status);
    }
}

How would it be more correct to declare properties and methods in this class?
Through a separate file (module):
interface cooking {
    public type: string;
    public model: string;
    public status: string;

    getStatus(t: string) : string;
}

class Cookies implement cooking ...

Or by creating a *.d.ts file:
declare namespace cooking {
    export interface cooking {
        public type: string;
        public model: string;
        public status: string;

        getStatus(t: string) : string;
    }
}

And in general, is the use of *.d.ts files for describing types relevant, or should they be used only if external libraries not written in typescript are connected?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-08-10
@azovl

In this case, there is no need to describe anything separately - everything is described in the code. *.d.ts are needed only if either is written in JS, but it must be included from TS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question