Autodesk / Autodesk/react-base-table
Type of Alignment (and other constants) in types/index.d.ts is a 'type' instead of a 'value'
- Lingua principale
- TypeScript
- Stelle
- 1.5k
- Fork
- 170
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Leggi types/index.d.ts insieme a index.js e alle dichiarazioni di Column per determinare se il package intende rendere Alignment disponibile sia come valore sia come tipo. Convalida la dichiarazione scelta rispetto agli esempi di importazione nell'issue; il lavoro è completato quando gli utenti di TypeScript possono usare la costante esportata in modo coerente con Column.Alignment senza oscurare l'uso dei tipi esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react, typescript
- Ambito
- frontend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100