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
[WIP] build: migrate to Typescript #2326
base: main
Are you sure you want to change the base?
Conversation
Wow. |
This is exciting! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! It so nice to see some those comments reference flow bugs go away. It's too bad about all of the test failures. I'll check out your branch sometime this week and try to make some progress with these failing tests.
|
||
import {defineSymbol} from './src/symbols'; | ||
import {defineMacro} from './src/macros'; | ||
import {setFontMetrics} from './src/fontMetrics'; | ||
|
||
declare var __VERSION__: string; | ||
declare const __VERSION__: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize the TS added support for this. Cool!
@@ -88,7 +81,7 @@ const generateParseTree = function( | |||
* error message. Otherwise, simply throws the error. | |||
*/ | |||
const renderError = function( | |||
error, | |||
error: any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call making types for function params required. Even if we need to add a bunch of any
s it makes it easier to see places where the typing could be better.
@@ -30,7 +28,7 @@ export const implicitCommands = { | |||
export default class MacroExpander implements MacroContextInterface { | |||
settings: Settings; | |||
expansionCount: number; | |||
lexer: Lexer; | |||
lexer!: Lexer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the !
modifier do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbarabash !
is a non-null assertion operator, since feed
, which sets the lexer
, is always called.
@@ -317,7 +311,7 @@ export default class MacroExpander implements MacroContextInterface { | |||
* Returns the expanded macro as a reversed array of tokens and a macro | |||
* argument count. Or returns `null` if no such macro. | |||
*/ | |||
_getExpansion(name: string): ?MacroExpansion { | |||
_getExpansion(name: string): MacroExpansion | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to match flow semantics ?T
should be to T | null | undefined
. I'm not sure if this is what's causing the 300 errors. If it isn't though T | null
is probably better since it's more restrictive. FTR, I don't think that we should be trying to maintain flow semantics once we switch to TypeScript.
style: StyleInterface, | ||
color?: string | void, | ||
size?: number, | ||
textSize?: number, | ||
phantom?: boolean, | ||
font?: string, | ||
fontFamily?: string, | ||
fontWeight?: FontWeight, | ||
fontShape?: FontShape, | ||
sizeMultiplier?: number, | ||
maxSize: number, | ||
minRuleThickness: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that ;
was supposed to be used in types to separate properties in TypeScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It´s an Object. The values in an Object are seperated with a ,
.
|
||
constructor(type: MathNodeType, children?: $ReadOnlyArray<MathDomNode>) { | ||
constructor(type: MathNodeType, children?: Array<MathDomNode>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use ReadonlyArray
here?
// Making the type below exact with all optional fields doesn't work due to | ||
// - https://github.com/facebook/flow/issues/4582 | ||
// - https://github.com/facebook/flow/issues/5688 | ||
// However, since *all* fields are optional, $Shape<> works as suggested in 5688 | ||
// above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sad to see this comment go bye-bye. 😄
@@ -245,7 +245,7 @@ const svgSpan = function( | |||
let widthClasses; | |||
let aligns; | |||
if (numSvgChildren === 1) { | |||
// $FlowFixMe: All these cases must be of the 4-tuple type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to maintain this comment if it's still valid under TypeScript.
/** | ||
* Provide a default value if a setting is undefined | ||
* NOTE: Couldn't use `T` as the output type due to facebook/flow#5022. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay!
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
|
||
/* Advanced Options */ | ||
"skipLibCheck": true, /* Skip type checking of declaration files. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why this isn't the default. I have a personal project I'm using TS for and it took a lot of search to find out this not using this setting what was making build slow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbarabash This is default from tsc --init
@kevinbarabash Thank you for comments and the great tool! Most of changes are done by |
It seems somehow I ran an old version of |
Sounds good. I checked out the branch and started trying to fix things. I got the error count down to 253 but it's kind of slow going. Maybe we should add |
There is a TypeScript version of the mhchem parser. Using it for this pull request might save you some time. |
Closes #2110.
typescript-eslint
References:
Any comments and helps are appreciated! Please feel free to open a PR or commit directly against this branch.