Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export arrow function has no name #46

Open
fkworld opened this issue Jun 4, 2020 · 1 comment
Open

export arrow function has no name #46

fkworld opened this issue Jun 4, 2020 · 1 comment

Comments

@fkworld
Copy link
Owner

fkworld commented Jun 4, 2020

这是一个ts语言的相关bug,相关的issue也很多,但都还没有解决。

表现为:

const a = () => {};
export const b = () => {};
console.log(a.name === "a", b.name === "b", b.name === "");
// true false true

可以看到,如果是普通的箭头函数,则可以正确获取函数名;如果是被导出的箭头函数,则无法正确获取函数名。

因此,在此bug未被官方解决之前,建议使用export function来定义函数。同时,在tsconfig中添加noImplicitThis配置来防止this的滥用。

@fkworld fkworld mentioned this issue Jun 10, 2020
12 tasks
@fkworld
Copy link
Owner Author

fkworld commented Jun 20, 2020

在deno的编码规范中,有一条:

Top level functions should not use arrow syntax.

https://github.com/denoland/deno/blob/master/docs/contributing/style_guide.md#top-level-functions-should-not-use-arrow-syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant