TypeScript 允许跨文件的 "go do declaration" / "find references" 对于导出,foo = 缺少一些引用

yb3bgrhw  于 6个月前  发布在  TypeScript
关注(0)|答案(2)|浏览(53)

Bug报告

摘要:在使用allowJs exports.foo = foo;风格的导出和const {foo} = require(风格的导入时,"find references"和"go to declaration"在跨文件时会丢失引用。

🔎 搜索词

go to declaration
find all references
checkjs
allowjs

🕗 版本与回归信息

  • 在版本4.0.7和4.1.5之间发生了变化,但我认为4.0.7版本的行为也不理想

⏯ Playground链接

Bug Workbench无法演示此问题,因此我创建了一个指向github的Stackblitz复现链接。然而,出于某种原因,Stackblitz也无法复现它。
https://stackblitz.com/edit/typescript-repro-1
https://github.com/cspotcode/repros-stackblitz/tree/allowjs-declarations

💻 代码

// src/index.js
// BUG: "Go to definition" on foo shows "no definition found for foo"
// TS 4.0.5 BUG: "Go to definition" links to the first `foo` in `exports.foo = foo;`, whereas I believe it should link to `async function foo` to match .ts checking behavior.
// GOOD: "Find references" includes `exports.foo = foo;` from libfoo.js
// BUG: "Find references" does not include `async function foo` nor `foo()` from libfoo.js
const {foo} = require('./libfoo');

// GOOD: "Go to definition" on foo jumps to `async function foo` in libfoo.js
// GOOD: "Find references" includes `exports.foo = foo;`
// BUG: "Find references" does not include `async function foo` nor `foo()` from libfoo.js
foo();
// src/libfoo.js
// BUG: "Find references" on the local `foo` in this file does not include anything from `index.js`
// BUG: "Find references" on the `foo` in `exports.foo` in this file does not include anything; jumps to self.
// GOOD: "Go to definition" on the `foo` in `exports.foo` in this file jumps to `async function foo`

exports.foo = foo;
/** jsdoc here */
async function foo() {}

foo();

🙁 实际行为

foo上使用"Find references"时,会丢失其他文件中的引用。示例中的BUG:注解准确地列出了问题所在。

🙂 预期行为

所有foo标识符的"Go to definition"应链接到async function foo()
任何foo标识符的"Find references"应列出两个.js文件中的所有引用。

lx0bsm1f

lx0bsm1f1#

我更新了错误的"版本和回归信息"。

zqry0prt

zqry0prt2#

我们在社区Discord上讨论过这个问题。如果有帮助的话,这里有一个链接:https://discord.com/channels/508357248330760243/508357248330760249/826853657982533634

相关问题