Skip to content

export arrow function has no name #46

@fkworld

Description

@fkworld

这是一个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的滥用。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions