安装打字稿后,为什么要“窥视定义”。在Visual Studio代码中停止工作?

发布于 2025-01-28 19:32:08 字数 2115 浏览 1 评论 0原文

我是Typescript的新手,并且正在尝试弄清为什么在将项目转换为Visual Studio Code中的打字稿时,“ PEEK定义”停止工作。

在过渡到打字稿之前,我正在使用jsconfig.json来设置WebPack别名。添加Typescript后,我使用tsconfig.json来做同样的事情,而我尚不完全了解其他配置选项。

没有打字稿,当徘徊在组件上时,我会看到类似的内容,

(alias) module ComponentWrapper
(alias) const ComponentWrapper: {
    ({ children }: {
        children: any;
    }): JSX.Element;
    displayName: string;
    propTypes: {
        something: PropTypes.Requireable<string>;
    };
    defaultProps: {};
}
import ComponentWrapper

而CMD + Click会将我带到该文件。但是,在打字稿项目中,执行同样的事情,当悬停时,我会看到

import ComponentWrapper

和cmd + click只需将我带到文件的顶部到import语句。

我的jsconfig.json看起来

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@modules/*": ["src/modules/*"],
      "@utils/*": ["src/utils/*"]
    }
  }
}

像我的tsconfig.json看起来

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@modules/*": ["src/modules/*"],
      "@utils/*": ["src/utils/*"]
    },
    "allowJs": true,
    "checkJs": false,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "dom.iterable", "es2017"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmit": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "preserveConstEnums": true,
    "removeComments": false,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": false,
    "target": "ES2019",
    "incremental": true
  },
  "exclude": [".github", ".next", "node_modules", "public"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

我怎么了?

I'm very new to TypeScript and am trying to figure why, when transitioning a project to TypeScript in Visual Studio Code, "Peek Definition" stops working.

Before transitioning to TypeScript, I'm using jsconfig.json to set up Webpack aliases. After adding TypeScript, I'm using tsconfig.json to do the same thing, with additional configuration options I don't fully understand yet.

Without TypeScript, when hovering over a component, I'll see something like,

(alias) module ComponentWrapper
(alias) const ComponentWrapper: {
    ({ children }: {
        children: any;
    }): JSX.Element;
    displayName: string;
    propTypes: {
        something: PropTypes.Requireable<string>;
    };
    defaultProps: {};
}
import ComponentWrapper

And CMD + click will take me to that file. However, in the TypeScript project, doing the same thing, when hovering I see

import ComponentWrapper

And CMD + click just takes me to the top of the file to the import statement.

My jsconfig.json looks like

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@modules/*": ["src/modules/*"],
      "@utils/*": ["src/utils/*"]
    }
  }
}

While my tsconfig.json looks like

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@modules/*": ["src/modules/*"],
      "@utils/*": ["src/utils/*"]
    },
    "allowJs": true,
    "checkJs": false,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "dom.iterable", "es2017"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmit": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "preserveConstEnums": true,
    "removeComments": false,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": false,
    "target": "ES2019",
    "incremental": true
  },
  "exclude": [".github", ".next", "node_modules", "public"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

What am I getting wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文