Skip to content

v9: decode does not work with import * in TypeScript #875

Open
@bluepichu

Description

@bluepichu

Description

If you import * as jwt from "jsonwebtoken", then you can't call jwt.decode. It works fine if you use a default import though (import jwt from "jsonwebtoken").

Related to #866, and probably also #870.

The root cause of this is that import * in TS gets translated in such a way that only enumerable properties are copied from the module. Since decode is non-enumerable it is not properly copied.

Reproduction

import * as jwt from "jsonwebtoken";

jwt.decode("abc"); // TypeError: jwt.decode is not a function

Environment

Version 9.0.0 on Node 16.19.0 with TS 4.6.2

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