Skip to content

how to define project owned typescript declaration #401

Description

@honwhy

Describe the bug

failed to define project owned typescript declaration

To Reproduce

in content script, import vue sfc file, and in sfc file import 'turndown'

turndown
try to declare module, and add to <rootDir>/tsconfig.json

export {}

declare module 'turndown' {
  export class TurndownService {}
}

in <rootDir>/tsconfig.json,

{
  "extends": "./.wxt/tsconfig.json"
+ "include": ["./global.d.ts"]
}

but results in more typescript errors

Expected behavior

Screenshots

image

Activity

  1. added
    pending-triageSomeone (usually a maintainer) needs to look into this to see if it's a bug
    on Feb 3, 2024
  2. removed
    pending-triageSomeone (usually a maintainer) needs to look into this to see if it's a bug
    on Feb 3, 2024
  3. aklinker1 commented on Feb 3, 2024

    @aklinker1
    Member

    TLDR: Remove export {} from your declaration file and remove "include" from your tsconfig.json, then everything will work.


    When your TSConfig files extends another and you set the include or exclude options, the extended include and exclude options are overridden, not merged.

    So in your case, you're telling typescript to only include your global file in the project, and none of your source code. Look at .wxt/tsconfig.json for what include defaults to for your project.

    As for the export {}, this makes a declaration file a module, not a declaration file, and that means you have to import it before you get any of the declarations you defined in it.

    In general, you don't add export {} when declaring modules.

  4. nnx0r commented on Feb 3, 2024

    @nnx0r
    Contributor

    Move to discussion, I'd say. Someone else may have same/similar question in the future.

  5. locked and limited conversation to collaborators on Feb 3, 2024
  6. converted this issue into a discussion #403 on Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions