question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TypeScript] Multiple errors on TableCell components

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

No typescript errors.

Current Behavior

Hello, I’m having some typescript issues with TableCell props direction and sortDirection

TS2322: Type 'string' is not assignable to type 'SortDirection'. TS2322: Type 'string' is not assignable to type 'asc' | 'desc'.

I experienced those errors on an other library and the fixed was by passing it with an Enum instead of a type for ‘asc’ or ‘dsc’. Example :

export type SortDirection = Direction | false; export const enum Direction { ASC = 'asc', DSC='desc' }

Steps to Reproduce

I’m not able to reproduce on the codesanbox, it’s weird.

Link : https://codesandbox.io/s/jz25ov7p5w

Context

I can’t compile.

Your Environment

tsconfig.json and tslint.json files are in the codesanbox

Tech Version
Material-UI 3.1.1
React 16.5.2
Browser
TypeScript 3.1.3
etc.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
eps1loncommented, Oct 24, 2018

You encountered typescripts type widening.

Possible fix:

interface State {
  order: 'asc' | 'desc'
  orderBy: string;
}

class Index extends React.Component<{}, State> {
  state: State = {
    order: "asc",
    orderBy: "calories"
  };
  ...
}

codesandbox’ typechecking is currently not working. That’s why you couldn’t reproduce this.

0reactions
eps1loncommented, Oct 25, 2018

Yes which is caused by typescript. I provided you with the proper documentation about that typescript behavior. It has nothing to do with this library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[TypeScript] Multiple errors on TableCell components #13372
No typescript errors. Current Behavior. Hello, I'm having some typescript issues with TableCell props direction and sortDirection. TS2322: Type ...
Read more >
Something went wrong with react table using typescript
It is possible that you are missing the @types/react-table package. If the package is installed already, there is another step to follow to ......
Read more >
Grid - How do I resolve these typescript errors relating to type ...
a) I think this works in JS as restProps contain these elements and they are passed through. Typescript wants them explicitly.
Read more >
HTML DOM Table cells Collection - W3Schools
The cells collection returns a collection of all <td> or <th> elements in a table. Note: The elements in the collection are sorted...
Read more >
Data Grid - Editing - MUI X
To let your users edit all cells in a given row simultaneously, set the editMode prop to "row" . For more information, see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found