最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript compiler error TS1005: ',' expected - Stack Overflow

programmeradmin3浏览0评论

Am getting a piler error with typescript.

[tsl] ERROR in /.../node_modules/@remirror/react-ponents/node_modules/@mui/base/useMenu/useMenu.d.ts(3,15)
      TS1005: ',' expected.
ts-loader-default_e3b0c44298fc1c14

In the file, an import is causing the error:

import { type MenuUnstyledContextType } from '../MenuUnstyled';

'type' is declared but its value is never read.ts(6133)
Module '"../MenuUnstyled"' has no exported member 'type'. Did you mean to use 'import type from "../MenuUnstyled"' instead?ts(2614)

That appears to be valid in typescript 3.8 though, and the app uses typescript ^4.3.5 and @babel/preset-typescript ^7.14.5.

.html#:~:text=With%20TypeScript%203.8%2C%20you%20can,statement%2C%20or%20using%20import%20type%20

// Explicitly pull out a value (getResponse) and a type (APIResponseType) 
import { getResponse, type APIResponseType} from "./api";

Any ideas how to resolve it?

Am getting a piler error with typescript.

[tsl] ERROR in /.../node_modules/@remirror/react-ponents/node_modules/@mui/base/useMenu/useMenu.d.ts(3,15)
      TS1005: ',' expected.
ts-loader-default_e3b0c44298fc1c14

In the file, an import is causing the error:

import { type MenuUnstyledContextType } from '../MenuUnstyled';

'type' is declared but its value is never read.ts(6133)
Module '"../MenuUnstyled"' has no exported member 'type'. Did you mean to use 'import type from "../MenuUnstyled"' instead?ts(2614)

That appears to be valid in typescript 3.8 though, and the app uses typescript ^4.3.5 and @babel/preset-typescript ^7.14.5.

https://www.typescriptlang/docs/handbook/modules.html#:~:text=With%20TypeScript%203.8%2C%20you%20can,statement%2C%20or%20using%20import%20type%20

// Explicitly pull out a value (getResponse) and a type (APIResponseType) 
import { getResponse, type APIResponseType} from "./api";

Any ideas how to resolve it?

Share Improve this question asked Mar 15, 2023 at 20:20 11928051192805 1,0483 gold badges14 silver badges30 bronze badges 1
  • 1 @jabaa Not since November 2021 :-) – Bergi Commented Mar 15, 2023 at 21:48
Add a ment  | 

2 Answers 2

Reset to default 13

That appears to be valid in typescript 3.8 though

Unfortunately, it isn't - the docs you found are very much misleading.

TypeScript 3.8 introduced type-only imports only with the import type … syntax:

As a solution in TypeScript 3.8, we’ve added a new syntax for type-only imports and exports.

import type { SomeThing } from "./some-module.js";

export type { SomeThing };

import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there’s no remnant of it at runtime. Similarly, export type only provides an export that can be used for type contexts, and is also erased from TypeScript’s output.

The syntax you are looking for was introduced with TypeScript 4.5:

type Modifiers on Import Names

[A type import] works, but it would be nice to avoid two import statements for the same module. That’s part of why TypeScript 4.5 allows a type modifier on individual named imports, so that you can mix and match as needed.

import { someFunc, type BaseType } from "./some-module.js";
export class Thing implements BaseType {
    someMethod() {
        someFunc();
    }
}

So update your version of TypeScript, or change your import declaration to

import type { APIResponseType } from "./api";
import { getResponse } from "./api";

TypeScript 4.5.5 is patible with version 5.10.2

    
"devDependencies": {
  "@typescript-eslint/eslint-plugin": "^5.10.2",
  "@typescript-eslint/parser": "^5.10.2",
}

https://stackoverflow./a/64626605/7166178

发布评论

评论列表(0)

  1. 暂无评论