Skip to content

Commit ac27df4

Browse files
committed
ArticleEditor: fix more types related to refs
1 parent 1a948b3 commit ac27df4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/perseus-editor/src/article-editor.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,14 @@ export default class ArticleEditor extends React.Component<Props, State> {
362362

363363
serialize(): JsonType {
364364
if (this.props.mode === "edit") {
365+
// Note(jeremy): Fixing this type error involves some extensive
366+
// re-working of the may <Editor /> component. Today it accepts a
367+
// `replace` prop (I _think_ because it's also used for editing
368+
// hints), but when I tried to re-work it I couldn't decipher which
369+
// types to fix and which to not fix.
370+
// @ts-expect-error - TS2322 - Type 'undefined' is not assignable to type 'PerseusRenderer'.ts
365371
return this._sections().map((section, i) => {
366-
// eslint-disable-next-line react/no-string-refs
367-
// @ts-expect-error - TS2339 - Property 'serialize' does not exist on type 'ReactInstance'.
368-
return this.refs["editor" + i].serialize();
372+
return this.editorRefs[i]?.serialize();
369373
});
370374
}
371375
if (this.props.mode === "preview" || this.props.mode === "json") {
@@ -378,12 +382,12 @@ export default class ArticleEditor extends React.Component<Props, State> {
378382
}
379383

380384
/**
381-
* Returns an array, with one element be section.
385+
* Returns an array, with one element per section.
382386
* Each element is an array of lint warnings present in that section.
383387
*
384388
* This function can currently only be called in edit mode.
385389
*/
386-
getSaveWarnings(): ReadonlyArray<Renderer> {
390+
getSaveWarnings(): ReadonlyArray<ReadonlyArray<string>> {
387391
if (this.props.mode !== "edit") {
388392
// TODO(joshuan): We should be able to get save warnings in
389393
// preview mode.
@@ -394,9 +398,7 @@ export default class ArticleEditor extends React.Component<Props, State> {
394398
}
395399

396400
return this._sections().map((section, i) => {
397-
// eslint-disable-next-line react/no-string-refs
398-
// @ts-expect-error - TS2339 - Property 'getSaveWarnings' does not exist on type 'ReactInstance'.
399-
return this.refs["editor" + i].getSaveWarnings();
401+
return this.editorRefs[i]?.getSaveWarnings() ?? [];
400402
});
401403
}
402404

0 commit comments

Comments
 (0)