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

javascript - Cannot use exports as a type because exports is a value - Stack Overflow

programmeradmin2浏览0评论

I get this error when running flow check, but I'm not sure what it means.

Cannot use exports as a type because exports is a value. To get the type of a value use typeof.

The error location is 0:1 (at the @flow comment). Here's the code:

/* @flow */
import Chunk from '../models/Chunk'

export interface IChunkSorter {
  sort(chunks: Chunk[]): Chunk[];
}

Any ideas? I've googled for the error message but there's literally no results.

I get this error when running flow check, but I'm not sure what it means.

Cannot use exports as a type because exports is a value. To get the type of a value use typeof.

The error location is 0:1 (at the @flow comment). Here's the code:

/* @flow */
import Chunk from '../models/Chunk'

export interface IChunkSorter {
  sort(chunks: Chunk[]): Chunk[];
}

Any ideas? I've googled for the error message but there's literally no results.

Share Improve this question edited Mar 27, 2018 at 9:06 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Mar 27, 2018 at 8:55 damddamd 6,95710 gold badges54 silver badges79 bronze badges 2
  • What is the definition of a Chunk? If it is a type, you should import it with import type .... Otherwise define type ChunkType = typeof Chunk and use it sort(chunks: ChunkType[]): ChunkType[]; – Aleksey L. Commented Mar 27, 2018 at 10:08
  • @AlekseyL. Chunk is a class and I still get the same error when I use what you suggested :/ – damd Commented Mar 27, 2018 at 11:37
Add a comment  | 

2 Answers 2

Reset to default 20

The problem was in a completely different file where I was importing IChunkSorter incorrectly. I was using:

import type IChunkSorter from './IChunkSorter'

This fixed it:

import type { IChunkSorter } from './IChunkSorter'

I had the same issue when exporting an enum as a type. I fixed the issue by exporting the enum as I would do with a regular constant: export MyEnum.

发布评论

评论列表(0)

  1. 暂无评论