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

[WIP] build: migrate to Typescript #2326

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

[WIP] build: migrate to Typescript #2326

wants to merge 11 commits into from

Conversation

ylemkimon
Copy link
Member

@ylemkimon ylemkimon commented Jul 20, 2020

@ronkok
Copy link
Collaborator

ronkok commented Jul 21, 2020

Wow.

@kevinbarabash
Copy link
Member

This is exciting!

Copy link
Member

@kevinbarabash kevinbarabash left a 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;
Copy link
Member

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,
Copy link
Member

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 anys 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;
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member

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.

Comment on lines +43 to +54
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
Copy link
Member

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.

Copy link

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>) {
Copy link
Member

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?

Comment on lines -20 to -24
// 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.
Copy link
Member

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.
Copy link
Member

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.

Comment on lines -16 to -19
/**
* Provide a default value if a setting is undefined
* NOTE: Couldn't use `T` as the output type due to facebook/flow#5022.
*/
Copy link
Member

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. */
Copy link
Member

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.

Copy link
Member Author

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

@ylemkimon
Copy link
Member Author

ylemkimon commented Aug 2, 2020

@kevinbarabash Thank you for comments and the great tool! Most of changes are done by flow-to-ts 😄 I didn't have to do a thing. I'll file issues I've encountered there.

@ylemkimon
Copy link
Member Author

It seems somehow I ran an old version of flow-to-ts. I'll update the PR, once we have stable codebase with recent PRs merged.

@kevinbarabash
Copy link
Member

I'll update the PR, once we have stable codebase with recent PRs merged.

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 @ts-ignores with a TODO to fix it later for any TypeScript error that isn't super easy to fix. That way we don't have to worry about the PR getting stale and we can fix the errors in smaller chunks after it gets merged.

@ronkok ronkok mentioned this pull request Aug 9, 2020
@ylemkimon ylemkimon changed the title [WIP] chore: migrate to Typescript [WIP] build: migrate to Typescript Aug 21, 2020
@mhchem
Copy link

mhchem commented Sep 2, 2020

There is a TypeScript version of the mhchem parser. Using it for this pull request might save you some time.

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

Successfully merging this pull request may close these issues.

Consider using TypeScript instead of Flow
5 participants