7

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?

7
  • probably this article contains the answer to your question Commented Oct 3, 2021 at 22:59
  • It's a bit confusing. I read that people are moving away from typeRoots in favor of include'ing it all Commented Oct 3, 2021 at 23:00
  • 1
    Do you have triple slash directives declared anywhere in role.d.ts? Commented Oct 20, 2021 at 16:02
  • Nope - what does that mean? Commented Oct 20, 2021 at 16:03
  • Hm interesting. The reference directive (specifically /// <reference types="...">) lets you specify a dependency between different type files. I was thinking you might have missed the reference for company.d.ts but you say you don't have any references at all yet Recruiter and File work. Commented Oct 20, 2021 at 16:24

2 Answers 2

5
+25

try export interface Company instead declare interface Company maybe solved!

Sign up to request clarification or add additional context in comments.

Comments

5

A special comment tells the typescript compiler to include another type-definition file

/// <reference path="myCustomDecls.d.ts" />

This should be used only in other .d.ts-files

For the typescript compiler to actually acknowledge your .d.ts-files you'll also have to specify them in the "compilerOptions" -> "typeroots" like this

"compilerOptions": {
  "typeRoots": ["./types/"] // directory containing .d.ts-files
}

If you have multiple custom declaration files, I'd recommend creating an index.d.ts file, that includes all your custom .d.ts-files using the first mentioned "special comment"

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.