Skip to content

Move some files to typescript - #264

Open
ViableSystemModel wants to merge 9 commits into
michelson:masterfrom
ViableSystemModel:typing.change-file-extensions
Open

Move some files to typescript#264
ViableSystemModel wants to merge 9 commits into
michelson:masterfrom
ViableSystemModel:typing.change-file-extensions

Conversation

@ViableSystemModel

Copy link
Copy Markdown

I tried to make this easier to review than the last PR. I’d change a file and then make as few changes as possible to get it to play nicely with rollup without errors. I think my increased familiarity with the codebase, emotion, and tiptap helped as well. Please let me know if this was an improvement.

If you have concerns about the module declarations to extend the libraries’ interfaces, I’m not sure what alternatives there are, but that does appear to be the prescribed way to add emotion themes and tiptap commands.

onBeforeCreate() {
// Before the view is created.
options.onBeforeCreate && options.onBeforeCreate(editor);
options.onBeforeCreate && options.onBeforeCreate(this.editor);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is needed this.editor? is this working?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually two ways to do this because it looks like tiptap both passes the object in and binds the function to it.

So this:

methodName({ editor }) {
    doThingWith(editor)
}

Can become:

methodName() {
    doThingWith(this.editor)
}

Or this:

methodName(this: { editor }) {
    doThingWith(editor)
}

But if you do the second one, it seems like it no longer recognizes the type of the editor argument for some reason.

Given that these functions are being bound to the object within tiptap and their this argument is very well typed, I assume this works. It also matches their documentation. I did some minimal testing to make sure I didn't massively break anything, but I'm sure it needs more attention.

placeholder: "Write something …",
showOnlyWhenEditable: true,
showOnlyCurrent: true,
addOptions() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this converted into a function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has something to do with the internals of tiptap's type inference. It's how they recommend doing it in the typescript compatibility section of their docs and it was causing an error to leave it as-is

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, 👌

return (
<AnchorStyle
fixed={fixed}
//fixed={fixed} // This wasn't present in the type for AnchorStyle and didn't appear to be referenced anywhere

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets keep this for now

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be able to add fixed as a prop to AnchorStyle, but I'm still trying to figure out how to work with the types on those styled components

<DanteTooltipLink
selected={editor.isActive("link")}
editor={editor}
//editor={editor}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep this from now

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I'll add the editor into the tooltip props instead.

width: 0;
position: absolute;
left: ${(props) => (props.arrowPosition ? props.arrowPosition : "50%")};
left: ${(props) => (props['arrowPosition'] ? props['arrowPosition'] : "50%")};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That property wasn't showing up on the props type signature, but the type was indexable by arbitrary strings. I can try typing the styled div with a <{arrowPosition: string}> generic and see if that works. It would certainly be less hacky.

@michelson michelson left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some questions on details

@michelson

Copy link
Copy Markdown
Owner

I will test this PR over the weekend, thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants