-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[TypeScript] Multiple errors on TableCell components #13372
Comments
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. |
Ok thank you very much @eps1lon, it fixed my compile errors. I used this example code: Should we fix it ? Is it a material-ui bug or a wront typescript implementation ? |
Is the issue with types or at runtime? You can't just simply copy code from javascript and call it typescript. At least not in most cases. |
The issue is with types, I can't compile without your fix @eps1lon |
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. |
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
The text was updated successfully, but these errors were encountered: