Autodesk / Autodesk/react-base-table

Type of Alignment (and other constants) in types/index.d.ts is a 'type' instead of a 'value'

オープン
#298 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
1.5k
フォーク
170
PR マージ指標
30日以内にマージされた PR はありません

説明

Currently, Alignment is exported as a variable directly in index.js
```
export { default as Column, Alignment, FrozenDirection } from './Column';
```
and is defined as
```
export const Alignment = {
LEFT: 'left',
CENTER: 'center',
RIGHT: 'right',
};
```

However, in types/index.d.ts, Alignment is specified as
```
export type Alignment = 'left' | 'right' | 'center';
```
which is a type, not a value. This means that a statement like
```
import { Alignment } from 'react-base-table'

const column = {
align: Alignment.CENTER
}
```

Will fail if compiled with typescript, since types cannot be used as values:
```
'Alignment' only refers to a type, but is being used as a value here.ts(2693)
```

Later in types/index.d.ts, Column.Alignment is typed:
```
export class Column extends React.Component> {
static readonly Alignment: {
readonly LEFT: 'left';
readonly CENTER: 'center';
readonly RIGHT: 'right';
};
static readonly FrozenDirection: {
readonly LEFT: 'left';
readonly RIGHT: 'right';
readonly DEFAULT: true;
readonly NONE: false;
};
}
```
So the code
```
import { Column } from 'react-base-table'

const column = {
align: Column.Alignment.CENTER
}
```
Will compile.

Alignment should likely be typed the same way, since Column.Alignment === Alignment.

Not sure exactly what the right solution is, since changing the types now is technically a breaking change to the types (Someone could currently be doing something like:
```
import { Column, Alignment } from 'react-base-table'

const myColumnAlignment: Alignment = Column.Alignment.CENTER
```

It's unclear to me if this is just happenstance, or it was actually intended.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

types/index.d.ts を index.js および Column の宣言と併せて読み、パッケージが Alignment を値と型の両方として利用可能にする意図があるかを判断します。Issue の import 例に対して選択した宣言を検証します。TypeScript ユーザーが既存の型の使用を不明瞭にすることなく、Column.Alignment と一貫した形でエクスポートされた定数を使用できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
react, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。