-
Notifications
You must be signed in to change notification settings - Fork 3.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
Turn on noImplicitAny
and fix all errors
#3845
Conversation
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 the contribution!
Thanks for the feedback! I still have some failing tests that I plan to address just FYI |
@luin tests and lint should all be passing if you want to run the workflow again |
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 the update. I think we should focus on changes to types in this PR and try to avoid changes to actual code when.
For changes to types, we can focus on function signatures and use // @ts-expect-error TODO fix this later
inside function unless it's a easy fix.
modules/tableEmbed.ts
Outdated
@@ -12,11 +12,17 @@ export type TableRowColumnOp = Omit<Op, 'insert'> & { | |||
}; | |||
|
|||
export interface TableData { | |||
rows?: Delta['ops']; | |||
columns?: Delta['ops']; | |||
rows?: Delta; |
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.
We should not change the declaration of a public module. Here Delta
should be a Delta['ops']
.
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.
The problem here is that tableEmbed.ts
is internally inconsistent. Functions like compactTableData()
take in a TableData
type but the code expects rows
and columns
here to be Deltas (it calls rows.length()
instead of checking rows.length
, as we would expect if the type really was an array of ops). So we have two options here:
- Change the declaration of the public module to match what the code actually does
- Change the code to match the public declaration
I originally went with option (2), but you asked me to change it to pass in Delta
s. So we need to decide which of those two options we want to go with and I'm happy to make the changes, but the point is that something will need to change here as the type annotations are revealing.
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 added the missing types without changing the actual code.
core/quill.ts
Outdated
if (range == null) return null; | ||
let start; | ||
let end; | ||
if (index && typeof index.transformPosition === 'function') { | ||
if (index && index instanceof Delta) { |
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.
We should avoid changing actual code. This brings a breaking change when users provide another Delta library or instance.
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 can change it back to check for the typeof the transformPosition function, but we will at least need to add a check here that the typeof index !== 'number'
(because index
is either a number or a Delta at this point and we don't know which). Without a better type guard there, we get this error:
Property 'transformPosition' does not exist on type 'number | Delta'.
Property 'transformPosition' does not exist on type 'number'. ts(2339)
I get the desire to avoid code changes and I did in fact try to avoid them wherever possible, but I erred on the side of adding better guards instead of just suppressing type errors. Our bug tracker at work reports tens of thousands of exceptions from Quill every day and part of my motivation with this PR was to find and fix the source of those 😄
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.
Yeah feel free to create issues so I can take a look at the errors. We could address them in separate PRs.
modules/tableEmbed.ts
Outdated
@@ -52,36 +58,39 @@ export const composePosition = (delta: Delta, index: number) => { | |||
return newIndex; | |||
}; | |||
|
|||
const compactCellData = ({ content, attributes }) => { | |||
const compactCellData = ({ content, attributes }: CellData) => { |
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.
We expect content
to be a Delta.
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.
See comment here: #3845 (comment)
test/unit/modules/tableEmbed.spec.ts
Outdated
@@ -47,15 +47,15 @@ describe('tableHandler', () => { | |||
{ | |||
insert: { | |||
'table-embed': { | |||
rows: [ | |||
rows: new Delta([ |
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.
Tests should not be changed unless it's related to types.
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.
See comment here: #3845 (comment)
27839b8
to
5ad404d
Compare
8adfcf7
to
a7497e7
Compare
Thanks for the contribution! |
As part of the conversion of the codebase to TypeScript, this PR turns on the TS
noImplicitAny
flag and fixes all the type errors surfaced as a result. A vast majority of them were fixed with type annotations, however there are quite a few areas where real code changes were made to fix things such as nullability problems or parameter type mismatches. Perhaps the most serious of which is inside the table embed, where the existing types assumed rows and cells were op arrays but the code was passing around full deltas.Feedback welcome!