Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 7f590c3

Browse files
committed
fix: remove non null assertions
1 parent 5603868 commit 7f590c3

File tree

10 files changed

+49
-47
lines changed

10 files changed

+49
-47
lines changed

example-hooks/public/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html lang="en" data-framework="relay">
33
<head>
4-
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1">
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<title>Relay • TodoMVC</title>
7-
<link rel="stylesheet" href="base.css">
8-
<link rel="stylesheet" href="index.css">
7+
<link rel="stylesheet" href="base.css" />
8+
<link rel="stylesheet" href="index.css" />
99
</head>
1010
<body>
1111
<div id="root"></div>
1212
<script type="text/javascript">
1313
// Force `fetch` polyfill to workaround Chrome not displaying request body
1414
// in developer tools for the native `fetch`.
15-
self.fetch = null;
15+
self.fetch = null
1616
</script>
1717
<script src="http://localhost:3000/webpack-dev-server.js"></script>
1818
<script src="js/app.js"></script>

example-hooks/ts/ErrorBoundaryWithRetry.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import * as React from "react"
22

33
interface Props {
4-
fallback: (error: Error) => JSX.Element
4+
fallback: (error: Error, retryFn: () => void) => JSX.Element
5+
}
6+
interface State {
7+
error: Error | null
58
}
69

7-
class ErrorBoundaryWithRetry extends React.Component<Props> {
10+
class ErrorBoundaryWithRetry extends React.Component<Props, State> {
811
state = { error: null }
912

13+
// @ts-ignore
1014
static getDerivedStateFromError(error) {
1115
return { error: error }
1216
}
@@ -21,7 +25,7 @@ class ErrorBoundaryWithRetry extends React.Component<Props> {
2125

2226
if (error) {
2327
if (typeof fallback === "function") {
24-
return fallback(error, this._retry)
28+
return fallback(error!, this._retry)
2529
}
2630
return fallback
2731
}

example-hooks/ts/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import "todomvc-common"
1414

15-
import * as React from "react"
16-
import * as ReactDOM from "react-dom"
15+
import React from "react"
16+
import ReactDOM from "react-dom"
1717

1818
import { RelayEnvironmentProvider } from "react-relay"
1919
import { Environment, Network, RecordSource, Store } from "relay-runtime"

example-hooks/ts/components/Todo.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1010
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1111
*/
12+
import React from "react"
1213

1314
import ChangeTodoStatusMutation from "../mutations/ChangeTodoStatusMutation"
1415
import RemoveTodoMutation from "../mutations/RemoveTodoMutation"
1516
import RenameTodoMutation from "../mutations/RenameTodoMutation"
1617
import TodoTextInput from "./TodoTextInput"
1718

18-
import * as React from "react"
1919
import { graphql, useRelayEnvironment, useFragment } from "react-relay"
2020

2121
import classnames from "classnames"
@@ -58,7 +58,7 @@ const Todo = (props: Props) => {
5858

5959
const handleCompleteChange = (e: ChangeEvent<HTMLInputElement>) => {
6060
const complete = e.target.checked
61-
ChangeTodoStatusMutation.commit(environment, complete, todo!, viewer!)
61+
ChangeTodoStatusMutation.commit(environment, complete, todo, viewer)
6262
}
6363
const handleDestroyClick = () => {
6464
removeTodo()
@@ -75,18 +75,18 @@ const Todo = (props: Props) => {
7575
}
7676
const handleTextInputSave = (text: string) => {
7777
setIsEditing(false)
78-
RenameTodoMutation.commit(environment, text, todo!)
78+
RenameTodoMutation.commit(environment, text, todo)
7979
}
8080
function removeTodo() {
81-
RemoveTodoMutation.commit(environment, todo!, viewer!)
81+
RemoveTodoMutation.commit(environment, todo, viewer)
8282
}
8383

8484
function renderTextInput() {
8585
return (
8686
<TodoTextInput
8787
className="edit"
8888
commitOnBlur={true}
89-
initialValue={todo!.text}
89+
initialValue={todo.text}
9090
onCancel={handleTextInputCancel}
9191
onDelete={handleTextInputDelete}
9292
onSave={handleTextInputSave}
@@ -103,12 +103,12 @@ const Todo = (props: Props) => {
103103
>
104104
<div className="view">
105105
<input
106-
checked={!!todo!.complete}
106+
checked={!!todo.complete}
107107
className="toggle"
108108
onChange={handleCompleteChange}
109109
type="checkbox"
110110
/>
111-
<label onDoubleClick={handleLabelDoubleClick}>{todo!.text}</label>
111+
<label onDoubleClick={handleLabelDoubleClick}>{todo.text}</label>
112112
<button className="destroy" onClick={handleDestroyClick} />
113113
</div>
114114
{isEditing && renderTextInput()}

example-hooks/ts/components/TodoApp.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TodoList from "./TodoList"
1515
import TodoListFooter from "./TodoListFooter"
1616
import TodoTextInput from "./TodoTextInput"
1717

18-
import * as React from "react"
18+
import React from "react"
1919
import { graphql, RelayProp, useFragment } from "react-relay"
2020

2121
import { TodoApp_viewer$key } from "../__relay_artifacts__/TodoApp_viewer.graphql"
@@ -39,10 +39,10 @@ const TodoApp = (props: Props) => {
3939
)
4040

4141
const handleTextInputSave = (text: string) => {
42-
AddTodoMutation.commit(props.relay.environment, text, viewer!)
42+
AddTodoMutation.commit(props.relay.environment, text, viewer)
4343
}
4444

45-
const hasTodos = (viewer!.totalCount || 0) > 0
45+
const hasTodos = (viewer.totalCount || 0) > 0
4646

4747
return (
4848
<div>
@@ -56,8 +56,8 @@ const TodoApp = (props: Props) => {
5656
placeholder="What needs to be done?"
5757
/>
5858
</header>
59-
<TodoList viewer={viewer!} />
60-
{hasTodos && <TodoListFooter viewer={viewer!} />}
59+
<TodoList viewer={viewer} />
60+
{hasTodos && <TodoListFooter viewer={viewer} />}
6161
</section>
6262
<footer className="info">
6363
<p>Double-click to edit a todo</p>

example-hooks/ts/components/TodoList.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import MarkAllTodosMutation from "../mutations/MarkAllTodosMutation"
1414
import Todo from "./Todo"
1515

16-
import * as React from "react"
16+
import React from "react"
1717
import { graphql, useFragment, useRelayEnvironment } from "react-relay"
1818

1919
import { TodoList_viewer$key } from "../__relay_artifacts__/TodoList_viewer.graphql"
@@ -49,22 +49,22 @@ const TodoList = (props: Props) => {
4949
props.viewer,
5050
)
5151

52-
const numTodos = viewer!.totalCount
53-
const numCompletedTodos = viewer!.completedCount
52+
const numTodos = viewer.totalCount
53+
const numCompletedTodos = viewer.completedCount
5454

5555
const handleMarkAllChange = (e: ChangeEvent<HTMLInputElement>) => {
5656
const complete = e.target.checked
57-
MarkAllTodosMutation.commit(environment, complete, viewer!.todos, viewer!)
57+
MarkAllTodosMutation.commit(environment, complete, viewer.todos, viewer)
5858
}
5959

6060
const renderTodos = () => {
61-
if (!viewer!.todos || !viewer!.todos.edges) {
61+
if (!viewer.todos || !viewer.todos.edges) {
6262
throw new Error("assertion failed")
6363
}
64-
return viewer!.todos.edges.map(edge => {
64+
return viewer.todos.edges.map(edge => {
6565
const node = edge && edge.node
6666
if (!node) throw new Error("assertion failed")
67-
return <Todo key={node.id} todo={node} viewer={viewer!} />
67+
return <Todo key={node.id} todo={node} viewer={viewer} />
6868
})
6969
}
7070

example-hooks/ts/components/TodoListFooter.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import RemoveCompletedTodosMutation from "../mutations/RemoveCompletedTodosMutation"
1414

15-
import * as React from "react"
15+
import React from "react"
1616
import { graphql, useRelayEnvironment, useFragment } from "react-relay"
1717

1818
import { TodoListFooter_viewer$key } from "../__relay_artifacts__/TodoListFooter_viewer.graphql"
@@ -46,14 +46,14 @@ const TodoListFooter = (props: Props) => {
4646
props.viewer,
4747
)
4848

49-
const numCompletedTodos = viewer!.completedCount || 0
50-
const numRemainingTodos = (viewer!.totalCount || 0) - numCompletedTodos
49+
const numCompletedTodos = viewer.completedCount || 0
50+
const numRemainingTodos = (viewer.totalCount || 0) - numCompletedTodos
5151

5252
const handleRemoveCompletedTodosClick = () => {
5353
RemoveCompletedTodosMutation.commit(
5454
environment,
55-
viewer!.completedTodos,
56-
viewer!,
55+
viewer.completedTodos,
56+
viewer,
5757
)
5858
}
5959

example-hooks/ts/components/TodoRoot.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import * as React from "react"
1+
import React from "react"
22
import { useLazyLoadQuery, graphql } from "react-relay"
33

44
import { TodoRootQuery } from "../__relay_artifacts__/TodoRootQuery.graphql"
55

66
import TodoApp from "./TodoApp"
77

8-
import ErrorBoundaryWithRetry from "../ErrorBoundaryWithRetry"
9-
108
const TodoRoot = () => {
119
const { viewer } = useLazyLoadQuery<TodoRootQuery>(
1210
graphql`
@@ -19,16 +17,15 @@ const TodoRoot = () => {
1917
{},
2018
)
2119

20+
// @ts-ignore
2221
return <TodoApp viewer={viewer} />
2322
}
2423

2524
const TodoRootWrapper = () => {
2625
return (
27-
<ErrorBoundaryWithRetry fallback={error => <div>{error.message}</div>}>
28-
<React.Suspense fallback={<div>Loading</div>}>
29-
<TodoRoot />
30-
</React.Suspense>
31-
</ErrorBoundaryWithRetry>
26+
<React.Suspense fallback={<div>Loading</div>}>
27+
<TodoRoot />
28+
</React.Suspense>
3229
)
3330
}
3431

example-hooks/ts/components/TodoTextInput.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1111
*/
1212

13-
import * as React from "react"
14-
import * as ReactDOM from "react-dom"
15-
import * as PropTypes from "prop-types"
13+
import React from "react"
14+
import ReactDOM from "react-dom"
15+
import PropTypes from "prop-types"
1616
import { ChangeEvent } from "react"
1717

1818
const ENTER_KEY_CODE = 13

example-hooks/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"noEmit": true,
77
"moduleResolution": "node",
88
"strict": true,
9-
"target": "es2015"
9+
"target": "es2015",
10+
"allowSyntheticDefaultImports": true
1011
},
1112
"exclude": ["node_modules"]
1213
}

0 commit comments

Comments
 (0)