Autodesk / Autodesk/react-base-table
Type of Alignment (and other constants) in types/index.d.ts is a 'type' instead of a 'value'
- Vorherrschende Sprache
- TypeScript
- Sterne
- 1.5k
- Forks
- 170
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Lies types/index.d.ts zusammen mit index.js und den Deklarationen von Column, um festzustellen, ob das Paket beabsichtigt, Alignment sowohl als Wert als auch als Typ verfügbar zu machen. Validiere die gewählte Deklaration anhand der Importbeispiele im Issue; abgeschlossen, wenn TypeScript-Nutzer die exportierte Konstante konsistent mit Column.Alignment verwenden können, ohne die bestehende Typverwendung zu verschleiern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- react, typescript
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100