2

One of the libraries (parse5) used by my project is exposing typing information (in .d.ts files) using the following syntax to import types:

import { type CharacterToken, type DoctypeToken, type TagToken, type EOFToken, type CommentToken } from '../common/token.js';

This is causing a bunch of typescript errors when running the application, since it looks like typescript doesn't recognise this why of importing types.

If I change the syntax to

import type { CharacterToken, DoctypeToken, TagToken, EOFToken, CommentToken } from '../common/token.js';

I don't get any error.

might it be that I'm using a wrong tsc version?

0

2 Answers 2

2

The syntax used in the 'parse5' package for importing types was introduced with Typescript 4.5: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names

I ran into the same problem on a project using typescript 4.4, and upgrading to 4.5 resolved the issue for me.

Checking the open issues on parse5 revealed that many people have the same problem, e.g. look at https://github.com/inikulin/parse5/issues/913#issuecomment-1520222908

Sign up to request clarification or add additional context in comments.

Comments

1

In TypeScript(3.8) you should use import type { SomeThing } from "./some-module.js";, not import { type SomeThing } from "./some-module.js";

More info

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.