Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saperdadsk opened this issue Apr 28, 2021 · 2 comments

Comments

@saperdadsk
Copy link
Contributor

saperdadsk commented Apr 28, 2021

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<T = unknown> extends React.Component<ColumnShape<T>> {
    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.

@nihgwu
Copy link
Contributor

nihgwu commented Jun 10, 2021

it's definitely not intended and the type definition in types/index.d.ts is wrong I think, I was completely new to TS when bringing typings into this package

@nihgwu
Copy link
Contributor

nihgwu commented Jun 13, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants