fast-reflexes / better-react-mathjax

MIT License
129 stars 16 forks source link

mathjax TypeScript error #6

Closed LennyLip closed 2 years ago

LennyLip commented 3 years ago

Hey, thanks for the app.

Trying to run https://codesandbox.io/s/better-react-mathjax-basic-example-latex-bj8gd?file=/src/App.js with typescript code, but got the following:

TypeScript error in /node_modules/mathjax-full/js/core/MmlTree/MmlFactory.d.ts(3,70):
Type 'MmlNodeClass' does not satisfy the constraint 'FactoryNodeClass<MmlNode>'.
  Types of parameters 'factory' and 'factory' are incompatible.
    Type 'Factory<MmlNode, FactoryNodeClass<MmlNode>>' is missing the following properties from type 'MmlFactory': MML, defaultKind, nodeMap, node  TS2344

    1 | import { AbstractNodeFactory } from '../Tree/NodeFactory.js';
    2 | import { MmlNode, MmlNodeClass } from './MmlNode.js';
  > 3 | export declare class MmlFactory extends AbstractNodeFactory<MmlNode, MmlNodeClass> {
      |                                                                      ^
    4 |     static defaultNodes: {
    5 |         [kind: string]: MmlNodeClass;
    6 |     };

skipLibCheck helped, but it seems it is not a good setting. Is this mathjax src issue?

fast-reflexes commented 3 years ago

Hi there!

Thanks for the submission! You link to the basic example with Latex and then the code seems related to MathML so I'm a bit in the dark here :) Could you elaborate on what you mean by "running it with TypeScript" (I understand what running something with TypeScript means but given the example you linked to, it's kind of unclear what you're trying to do).

From your code excerpt, it looks like you're not conforming to the MathJax 3 types as set forth by the npm package mathjax-full (from where the MathJax 3 types are, without any processing at all, imported). Since this is not part of the code in better-react-mathjax, a possible bug would have to be filed with the mathjax-full repo instead (as you also point out).

I can try to help you out but then you need to provide a sandbox where this error shows. TypeScript type errors can indeed be hard to troubleshoot sometimes, especially when they involve type parameters.

I would need to see more of your code to get a better picture of what you're doing here... Seems all these classes are your own so why does MathJax throw an error...? Are you maybe declaring a conflicting name? What happens if you change the name of your class MmlFactory. You could also look at the mathjax-full source to get a better understanding of the problem.

LennyLip commented 3 years ago

Thanks. Codesanbox has no issue with its default typescript configs. I will create the project later.

fast-reflexes commented 2 years ago

Since there has been no news in this issue for a long time, I'm closing it. Feel free to open if you can provide more info.