Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In my custom TypeScript declaration file, how can I include another declaration?

Tags:

typescript

I have a few declarations in src/types/*.d.ts and in my src/types/role.d.ts, I have:

declare interface Role {
  id: string;
  title: string;
  openings: string;
  jobDescriptionUrl?: string;
  minCompRange: number | string;
  maxCompRange: number | string;
  location: string;
  postCovidLocation: string;
  urgency: ROLE_URGENCY;
  equity: ROLE_EQUITY;
  company?: Company;
  color: string;
  status: ROLE_STATUS;
  deletedAt?: Date;
  hiredAt?: Date;
  createdAt: Date;
  pausedAt?: Date;
  managerEmail?: string;
  managerName?: string;
  isExcRole?: boolean;
  recruiter?: Recruiter;
  offer?: File;
}

Somehow, it finds the Recruiter and File, but Company, which is declared in src/types/company.d.ts:

declare interface Company {
  companyName: string;
  companyUrl: string;
}

doesn't get found. I get an error:

src/types/role.d.ts:14:12 - error TS2304: Cannot find name 'Company'.

14  company?: Company;
              ~~~~~~~

In my tsconfig.json, I have:

    "include": [
        "src/**/*.ts",
    ]

What am I doing wrong?

like image 366
Shamoon Avatar asked Oct 03 '21 22:10

Shamoon


People also ask

What is declaration merging in TypeScript?

For the purposes of this article, “declaration merging” means that the compiler merges two separate declarations declared with the same name into a single definition. This merged definition has the features of both of the original declarations.

What is type declaration in TypeScript?

TypeScript includes declaration files for all of the standardized built-in APIs available in JavaScript runtimes. This includes things like methods and properties of built-in types like string or function , top-level names like Math and Object , and their associated types.

Is it possible to generate TypeScript declaration files from JS library?

If you paste the JavaScript into a new TypeScript file, fix any trivial errors you may get and compile it using the definition flag, it may be able to get you a file that would at least be a starting point. Show activity on this post.


1 Answers

try export interface Company instead declare interface Company maybe solved!

like image 176
kian Avatar answered Dec 17 '22 12:12

kian