Unverified Commit b3d9fd2a authored by Will Heslam's avatar Will Heslam Committed by GitHub

Make getInlineScriptSource arg Readonly (#17281)

The rule [total-functions/no-unsafe-readonly-mutable-assignment](https://github.com/danielnixon/eslint-plugin-total-functions#total-functionsno-unsafe-readonly-mutable-assignment) triggers with this error message:
> Assigning a readonly type to a mutable type can lead to unexpected mutation in the readonly value

when invoking
```
      NextScript.getInlineScriptSource(this.props)
```
inside a `_document.tsx`'s render function.
due to `this.props` having the type:
```
props: Readonly<P> & Readonly<{ children?: ReactNode }>
```
in `@types/react`

On the other hand, this is a small, low-priority change (IMO), so an alternative work around is just to disable the lint rule for that line of course.

Lint, tests, and build passes.

Lint error was discovered using typescript@next, version `4.1.0-dev.20200921` and eslint-plugin-total-functions version `4.1.0`, but I tested the change to nextjs using typescript version `3.8.3`.
parent bc2282fa
...@@ -648,7 +648,7 @@ export class NextScript extends Component<OriginProps> { ...@@ -648,7 +648,7 @@ export class NextScript extends Component<OriginProps> {
)) ))
} }
static getInlineScriptSource(documentProps: DocumentProps): string { static getInlineScriptSource(documentProps: Readonly<DocumentProps>): string {
const { __NEXT_DATA__ } = documentProps const { __NEXT_DATA__ } = documentProps
try { try {
const data = JSON.stringify(__NEXT_DATA__) const data = JSON.stringify(__NEXT_DATA__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment