Skip to content

Commit b211377

Browse files
authored
refactor: enable TypeScript strict mode (#649)
1 parent 55b0890 commit b211377

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+753
-666
lines changed

packages/betsy/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type Listener = {
22
once: boolean
3-
cb: ({}) => void
3+
cb: (msg: any) => void
44
}
55

66
export class EventEmitter<T> {
@@ -44,7 +44,7 @@ export class EventEmitter<T> {
4444
this.addListener(event, cb, true)
4545
}
4646

47-
private addListener(event: keyof T, cb: ({}) => void, once: boolean) {
47+
private addListener(event: keyof T, cb: (msg: any) => void, once: boolean) {
4848
const listeners = this.events.get(event) || []
4949

5050
listeners.push({

packages/betsy/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"declaration": true,
1212
"pretty": true,
1313
"sourceMap": true,
14-
"inlineSources": true
14+
"inlineSources": true,
15+
"strict": true
1516
},
1617
"exclude": ["node_modules", "dist", "es", "lib", "src/**/*.test.ts"]
1718
}

packages/overmind-devtools-client/src/BackendConnector.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class WebsocketConnector {
1414
[event: string]: Function[]
1515
} = {}
1616

17-
private socket: WebSocket
17+
private socket!: WebSocket | null
1818
private messagesBeforeConnected: Array<[string, any, any]> = []
1919
private isOpen = false
20-
private currentPort: number
20+
private currentPort!: number
2121

2222
private schedulePing() {
2323
setTimeout(() => {
@@ -116,7 +116,7 @@ class WebsocketConnector {
116116
this.callbacks[event].push(cb)
117117
}
118118

119-
off(event, cb) {
119+
off(event: any, cb: any) {
120120
if (this.callbacks[event]) {
121121
this.callbacks[event].splice(this.callbacks[event].indexOf(cb), 1)
122122
}
@@ -130,7 +130,7 @@ class WebsocketConnector {
130130

131131
const nextEvaluationId = this.nextEvaluationId++
132132

133-
this.socket.send(
133+
this.socket!.send(
134134
JSON.stringify({
135135
type: event,
136136
data,
@@ -139,7 +139,7 @@ class WebsocketConnector {
139139
)
140140

141141
if (onEvaluated) {
142-
const cb = (data) => {
142+
const cb = (data: any) => {
143143
if (data.id === nextEvaluationId) {
144144
this.off('evaluated', cb)
145145
onEvaluated(data.error ? data.error : null, data.data)
@@ -152,18 +152,22 @@ class WebsocketConnector {
152152

153153
export class BackendConnector extends WebsocketConnector {
154154
onMessage = (onMessage: MessageCallback) => {
155-
this.on('message', (message) => {
155+
this.on('message', (message: any) => {
156156
onMessage(message)
157157
})
158158
}
159159

160160
onDisconnect = (onDisconnect: (name: string) => void) => {
161-
this.on('disconnect', (name) => {
161+
this.on('disconnect', (name: any) => {
162162
onDisconnect(name)
163163
})
164164
}
165165

166-
sendMessage(appName: string, eventName: string, payload: object = null) {
166+
sendMessage(
167+
appName: string,
168+
eventName: string,
169+
payload: object | undefined = undefined
170+
) {
167171
this.send('message', {
168172
appName,
169173
type: eventName,

packages/overmind-devtools-client/src/components/ActionOperator/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const ActionOperator: React.FunctionComponent<Props> = ({
4040
<span
4141
className={styles.operatorType}
4242
style={{
43-
backgroundColor: operator.error ? colors.red : null,
44-
color: operator.error ? colors.text : null,
43+
backgroundColor: operator.error ? colors.red : undefined,
44+
color: operator.error ? colors.text : undefined,
4545
}}
4646
>
4747
{operator.type}

packages/overmind-devtools-client/src/components/ActionPayload/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const ActionPayload: React.FunctionComponent = () => {
99
const state = useAppState()
1010
const actions = useActions()
1111
const reaction = useReaction()
12-
const input = React.useRef(null)
12+
const input = React.useRef<HTMLInputElement>(null)
1313

1414
React.useEffect(() => {
1515
reaction(
1616
() => state.currentApp.selectedActionQuery,
17-
() => setTimeout(() => input.current && input.current.focus())
17+
() => setTimeout(() => input.current && input.current!.focus())
1818
)
1919
}, [])
2020

@@ -32,7 +32,9 @@ const ActionPayload: React.FunctionComponent = () => {
3232
!state.currentApp.selectedActionQuery || state.isExecutingAction
3333
}
3434
placeholder={
35-
state.currentApp.selectedActionQuery ? 'Add some payload...' : null
35+
state.currentApp.selectedActionQuery
36+
? 'Add some payload...'
37+
: undefined
3638
}
3739
onKeyDown={(event) => {
3840
if (event.keyCode === 13) {

packages/overmind-devtools-client/src/components/ActionsTools/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const ActionsTools: React.FunctionComponent = () => {
2323
<ActionPayload />
2424
<div
2525
className={styles.button}
26-
onClick={state.isExecutingAction ? null : () => actions.executeAction()}
26+
onClick={
27+
state.isExecutingAction ? undefined : () => actions.executeAction()
28+
}
2729
style={{
2830
backgroundColor:
2931
!state.isExecutingAction && state.currentApp.selectedActionQuery

packages/overmind-devtools-client/src/components/Chart/index.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
2121
statePath,
2222
nestedCharts = chart.charts,
2323
}) => {
24-
const [expandedIds, setExpandedIds] = React.useState([])
24+
const [expandedIds, setExpandedIds] = React.useState<string[]>([])
2525
const state = useAppState()
2626
const actions = useActions()
2727

@@ -80,7 +80,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
8080
style={{
8181
backgroundColor: isActiveState
8282
? nameToColor(chart.path.join(delimiter))
83-
: null,
83+
: undefined,
8484
}}
8585
>
8686
<span className={textStyles.label}>{key}</span>
@@ -92,7 +92,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
9292
style={{
9393
backgroundColor: isActiveState
9494
? nameToColor(chart.path.join(delimiter))
95-
: null,
95+
: undefined,
9696
}}
9797
/>
9898
</div>
@@ -103,7 +103,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
103103
style={{
104104
borderColor: isActiveState
105105
? nameToColor(chart.path.join(delimiter))
106-
: null,
106+
: undefined,
107107
}}
108108
>
109109
<span className={textStyles.normal}>
@@ -129,7 +129,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
129129
style={{
130130
backgroundColor: isActiveState
131131
? nameToColor(chart.path.join(delimiter))
132-
: null,
132+
: undefined,
133133
}}
134134
/>
135135
</div>
@@ -138,7 +138,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
138138
style={{
139139
borderColor: isActiveState
140140
? nameToColor(chart.path.join(delimiter))
141-
: null,
141+
: undefined,
142142
}}
143143
>
144144
<div
@@ -147,11 +147,12 @@ const ChartComponent: React.FunctionComponent<Props> = ({
147147
>
148148
{Object.keys(nestedChart.states[key].on || {}).map(
149149
(onKey) => {
150-
let target: string
151-
if (nestedChart.states[key].on[onKey]) {
152-
target =
153-
nestedChart.states[key].on[onKey][target] ||
154-
nestedChart.states[key].on[onKey]
150+
let target: string | undefined
151+
if (nestedChart.states[key].on![onKey]) {
152+
const onValue = nestedChart.states[key].on![
153+
onKey
154+
] as any
155+
target = onValue.target || onValue
155156
}
156157
return (
157158
<div key={onKey} className={styles.stateItem}>
@@ -164,7 +165,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
164165
.concat(onKey)
165166
.join(delimiter)
166167
)
167-
: null
168+
: undefined
168169
}
169170
className={css(
170171
styles.stateNameCell,
@@ -226,7 +227,7 @@ const ChartComponent: React.FunctionComponent<Props> = ({
226227
style={{
227228
borderColor: isActiveState
228229
? nameToColor(chart.path.join(delimiter))
229-
: null,
230+
: undefined,
230231
}}
231232
>
232233
<span className={textStyles.normal}>

packages/overmind-devtools-client/src/components/Inspector/index.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function renderValue({
8888

8989
type PathKeyProps = {
9090
path: string
91-
onClickPath: (path: string[]) => void
91+
onClickPath?: (path: string[]) => void
9292
onToggleExpand?: (path: string[]) => void
9393
disabled: boolean
9494
delimiter: string
@@ -106,11 +106,11 @@ const PathKey: React.FunctionComponent<PathKeyProps> = ({
106106
className={styles.key}
107107
onClick={
108108
disabled
109-
? null
109+
? undefined
110110
: (event) => {
111111
event.stopPropagation()
112112
if (event.metaKey || event.ctrlKey) {
113-
onClickPath(path.split(delimiter))
113+
onClickPath?.(path.split(delimiter))
114114
} else if (onToggleExpand) {
115115
onToggleExpand(path.split(delimiter))
116116
}
@@ -124,7 +124,7 @@ const PathKey: React.FunctionComponent<PathKeyProps> = ({
124124

125125
type EditValueProps = {
126126
value: any
127-
onSubmit: (newState: string) => void
127+
onSubmit?: (newState: string) => void
128128
}
129129

130130
const EditValue: React.FunctionComponent<EditValueProps> = ({
@@ -146,12 +146,12 @@ const EditValue: React.FunctionComponent<EditValueProps> = ({
146146
onChange={(event) => setState(event.currentTarget.value)}
147147
onKeyDown={(event) => {
148148
if ((event.metaKey || event.ctrlKey) && event.keyCode === 13) {
149-
onSubmit(state)
149+
onSubmit?.(state)
150150
}
151151
}}
152152
className={styles.newState}
153153
style={{
154-
borderColor: isValid ? null : colors.red,
154+
borderColor: isValid ? undefined : colors.red,
155155
}}
156156
/>
157157
<span className={styles.ok}>CMD/CTRL + ENTER to save</span>
@@ -164,16 +164,16 @@ type NestedProps = {
164164
startBracket: string
165165
endBracket: string
166166
expandedPaths: string[]
167-
renderPaths: RenderPaths
167+
renderPaths?: RenderPaths
168168
delimiter: string
169169
path: string
170170
hasWrapper: boolean
171171
isArray: boolean
172172
value: any
173173
onToggleExpand: (path: string[]) => void
174174
onClickPath?: (path: string[]) => void
175-
selectedStatePath: string
176-
onSubmitState: (newState: string) => void
175+
selectedStatePath?: string
176+
onSubmitState?: (newState: string) => void
177177
}
178178

179179
const Nested: React.FunctionComponent<NestedProps> = React.memo(
@@ -209,7 +209,7 @@ const Nested: React.FunctionComponent<NestedProps> = React.memo(
209209
) : null}
210210
<EditValue
211211
value={isClass ? value.value : value}
212-
onSubmit={onSubmitState}
212+
onSubmit={onSubmitState!}
213213
/>
214214
</div>
215215
)
@@ -336,8 +336,8 @@ type ValueComponentProps = {
336336
hasWrapper: boolean
337337
onClickPath?: (path: string[]) => void
338338
delimiter: string
339-
selectedStatePath: string
340-
onSubmitState: (newState: string) => void
339+
selectedStatePath?: string
340+
onSubmitState?: (newState: string) => void
341341
}
342342

343343
const ValueComponent: React.FunctionComponent<ValueComponentProps> = React.memo(
@@ -358,7 +358,7 @@ const ValueComponent: React.FunctionComponent<ValueComponentProps> = React.memo(
358358
{path.length ? (
359359
<span className={styles.key}>{path.split(delimiter).pop()}:</span>
360360
) : null}
361-
<EditValue value={value} onSubmit={onSubmitState} />
361+
<EditValue value={value} onSubmit={onSubmitState!} />
362362
</div>
363363
)
364364
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
export function isObject(obj) {
1+
export function isObject(obj: any) {
22
return typeof obj === 'object' && !Array.isArray(obj) && obj !== null
33
}
44

5-
export function isArray(array) {
5+
export function isArray(array: any) {
66
return Array.isArray(array)
77
}
88

9-
export function isBoolean(bool) {
9+
export function isBoolean(bool: any) {
1010
return typeof bool === 'boolean'
1111
}
1212

13-
export function isString(string) {
13+
export function isString(string: any) {
1414
return typeof string === 'string'
1515
}
1616

17-
export function isNumber(number) {
17+
export function isNumber(number: any) {
1818
return typeof number === 'number'
1919
}
2020

21-
export function isNull(_null) {
21+
export function isNull(_null: any) {
2222
return _null === null
2323
}

packages/overmind-devtools-client/src/components/RuntimeConfig/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ const RuntimeConfig: React.FunctionComponent = () => {
2626

2727
try {
2828
if (effects.platform.isElectron()) {
29-
window.electronAPI.setNewPort(newPort)
29+
window.electronAPI!.setNewPort(newPort)
3030
} else if (effects.platform.isVSCodeExtension()) {
31-
const vscode = window.vscode || window.acquireVsCodeApi()
31+
const vscode =
32+
(window as any).vscode || (window as any).acquireVsCodeApi()
3233
vscode.postMessage({
3334
command: 'newPort',
3435
text: newPort,

0 commit comments

Comments
 (0)