Skip to content

Commit 4ec0239

Browse files
Unable 'strict' checks for TSC (#347)
1 parent 5073408 commit 4ec0239

32 files changed

+368
-285
lines changed

.eslintrc.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ overrides:
5454
'react/jsx-key': off
5555
'react/no-string-refs': off
5656
'@typescript-eslint/no-var-requires': off
57-
58-
# FIXME: blocked by improper type checking should be fixed
59-
# after we switch TSC in strict mode
57+
'@typescript-eslint/no-non-null-assertion': off
6058
'@typescript-eslint/no-unnecessary-boolean-literal-compare': off
6159
'@typescript-eslint/no-explicit-any': off
6260
'@typescript-eslint/dot-notation': off

package-lock.json

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@types/node": "18.15.5",
6060
"@types/react": "18.0.26",
6161
"@types/react-dom": "18.0.10",
62+
"@types/webpack-node-externals": "^3.0.0",
6263
"@typescript-eslint/eslint-plugin": "5.30.7",
6364
"@typescript-eslint/parser": "5.30.7",
6465
"cspell": "6.2.3",

scripts/serve-directory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ function consoleError(msg: string) {
2626

2727
http
2828
.createServer((request, response) => {
29-
const url = new URL(request.url, 'file:');
29+
const url = new URL(request.url!, 'file:');
3030
let filePath = url.pathname;
3131
if (filePath === '/') {
3232
filePath = '/index.html';
3333
}
3434
filePath = path.join(options.directory, filePath);
3535

3636
const extname = String(path.extname(filePath)).toLowerCase();
37-
const mimeTypes = {
37+
const mimeTypes: { [ext: string]: string } = {
3838
'.html': 'text/html',
3939
'.js': 'text/javascript',
4040
'.css': 'text/css',

src/components/GraphViewport.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ interface GraphViewportProps {
1010
typeGraph: TypeGraph | null;
1111
displayOptions: VoyagerDisplayOptions;
1212

13-
selectedTypeID: string;
14-
selectedEdgeID: string;
13+
selectedTypeID: string | null;
14+
selectedEdgeID: string | null;
1515

16-
onSelectNode: (id: string) => void;
16+
onSelectNode: (id: string | null) => void;
1717
onSelectEdge: (id: string) => void;
1818
}
1919

@@ -35,10 +35,13 @@ export default class GraphViewport extends Component<
3535

3636
// Handle async graph rendering based on this example
3737
// https://gist.github.com/bvaughn/982ab689a41097237f6e9860db7ca8d6
38-
_currentTypeGraph = null;
39-
_currentDisplayOptions = null;
38+
_currentTypeGraph: TypeGraph | null = null;
39+
_currentDisplayOptions: VoyagerDisplayOptions | null = null;
4040

41-
static getDerivedStateFromProps(props, state) {
41+
static getDerivedStateFromProps(
42+
props: GraphViewportProps,
43+
state: GraphViewportState,
44+
): GraphViewportState | null {
4245
const { typeGraph, displayOptions } = props;
4346

4447
if (
@@ -56,7 +59,10 @@ export default class GraphViewport extends Component<
5659
this._renderSvgAsync(typeGraph, displayOptions);
5760
}
5861

59-
componentDidUpdate(prevProps, prevState) {
62+
componentDidUpdate(
63+
prevProps: GraphViewportProps,
64+
prevState: GraphViewportState,
65+
) {
6066
const { svgViewport } = this.state;
6167

6268
if (svgViewport == null) {
@@ -150,7 +156,7 @@ export default class GraphViewport extends Component<
150156
}
151157
}
152158

153-
focusNode(id) {
159+
focusNode(id: string) {
154160
const { svgViewport } = this.state;
155161
if (svgViewport) {
156162
svgViewport.focusElement(id);

src/components/IntrospectionModal.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ interface IntrospectionModalProps {
3333

3434
export function IntrospectionModal(props: IntrospectionModalProps) {
3535
const { open, presets, onChange, onClose } = props;
36-
const presetNames = presets != null ? Object.keys(presets) : [];
37-
const hasPresets = presetNames.length > 0;
36+
const hasPresets = presets != null;
37+
const presetNames = hasPresets ? Object.keys(presets) : [];
3838

3939
const [submitted, setSubmitted] = useState({
4040
inputType: hasPresets ? InputType.Presets : InputType.SDL,
@@ -103,7 +103,7 @@ export function IntrospectionModal(props: IntrospectionModalProps) {
103103
function handleSubmit() {
104104
switch (inputType) {
105105
case InputType.Presets:
106-
onChange(buildClientSchema(presets[activePreset].data));
106+
onChange(buildClientSchema(presets?.[activePreset].data));
107107
break;
108108
case InputType.Introspection:
109109
// check for errors and check if valid

src/components/Voyager.tsx

+30-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { GraphQLSchema } from 'graphql/type';
99
import { buildClientSchema, IntrospectionQuery } from 'graphql/utilities';
1010
import {
1111
Children,
12-
type ReactElement,
1312
type ReactNode,
1413
useEffect,
1514
useMemo,
@@ -52,7 +51,7 @@ export interface VoyagerProps {
5251
}
5352

5453
export default function Voyager(props: VoyagerProps) {
55-
const initialDisplayOptions: VoyagerDisplayOptions = useMemo(
54+
const initialDisplayOptions = useMemo(
5655
() => ({
5756
rootType: undefined,
5857
skipRelay: true,
@@ -83,10 +82,19 @@ export default function Voyager(props: VoyagerProps) {
8382
return null;
8483
}
8584

86-
const introspectionSchema =
87-
introspectionResult.value instanceof GraphQLSchema
88-
? introspectionResult.value
89-
: buildClientSchema(introspectionResult.value.data);
85+
let introspectionSchema;
86+
if (introspectionResult.value instanceof GraphQLSchema) {
87+
introspectionSchema = introspectionResult.value;
88+
} else {
89+
if (
90+
introspectionResult.value.errors != null ||
91+
introspectionResult.value.data == null
92+
) {
93+
// FIXME: display errors
94+
return null;
95+
}
96+
introspectionSchema = buildClientSchema(introspectionResult.value.data);
97+
}
9098

9199
const schema = getSchema(
92100
introspectionSchema,
@@ -105,7 +113,13 @@ export default function Voyager(props: VoyagerProps) {
105113
setSelected({ typeID: null, edgeID: null });
106114
}, [typeGraph]);
107115

108-
const [selected, setSelected] = useState({ typeID: null, edgeID: null });
116+
const [selected, setSelected] = useState<{
117+
typeID: string | null;
118+
edgeID: string | null;
119+
}>({
120+
typeID: null,
121+
edgeID: null,
122+
});
109123

110124
const {
111125
allowToChangeSchema = false,
@@ -115,7 +129,7 @@ export default function Voyager(props: VoyagerProps) {
115129
hideVoyagerLogo = true,
116130
} = props;
117131

118-
const viewportRef = useRef(null);
132+
const viewportRef = useRef<GraphViewport>(null);
119133
useEffect(() => viewportRef.current?.resize(), [hideDocs]);
120134

121135
return (
@@ -143,7 +157,10 @@ export default function Voyager(props: VoyagerProps) {
143157
function renderPanel() {
144158
const children = Children.toArray(props.children);
145159
const panelHeader = children.find(
146-
(child: ReactElement) => child.type === Voyager.PanelHeader,
160+
(child) =>
161+
typeof child === 'object' &&
162+
'type' in child &&
163+
child.type === Voyager.PanelHeader,
147164
);
148165

149166
return (
@@ -156,7 +173,7 @@ export default function Voyager(props: VoyagerProps) {
156173
typeGraph={typeGraph}
157174
selectedTypeID={selected.typeID}
158175
selectedEdgeID={selected.edgeID}
159-
onFocusNode={(id) => viewportRef.current.focusNode(id)}
176+
onFocusNode={(id) => viewportRef.current?.focusNode(id)}
160177
onSelectNode={handleSelectNode}
161178
onSelectEdge={handleSelectEdge}
162179
/>
@@ -210,7 +227,7 @@ export default function Voyager(props: VoyagerProps) {
210227
);
211228
}
212229

213-
function handleSelectNode(typeID: string) {
230+
function handleSelectNode(typeID: string | null) {
214231
setSelected((oldSelected) => {
215232
if (typeID === oldSelected.typeID) {
216233
return oldSelected;
@@ -219,9 +236,9 @@ export default function Voyager(props: VoyagerProps) {
219236
});
220237
}
221238

222-
function handleSelectEdge(edgeID: string) {
239+
function handleSelectEdge(edgeID: string | null) {
223240
setSelected((oldSelected) => {
224-
if (edgeID === oldSelected.edgeID) {
241+
if (edgeID === oldSelected.edgeID || edgeID == null) {
225242
// deselect if click again
226243
return { ...oldSelected, edgeID: null };
227244
} else {

src/components/doc-explorer/Argument.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import WrappedTypeName from './WrappedTypeName';
88

99
interface ArgumentProps {
1010
arg: GraphQLArgument;
11-
filter: string;
11+
filter: string | null;
1212
expanded: boolean;
1313
onTypeLink: (type: GraphQLNamedType) => void;
1414
}

src/components/doc-explorer/Description.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import './Description.css';
33
import Markdown from '../utils/Markdown';
44

55
interface DescriptionProps {
6-
text?: string;
6+
text: string | undefined | null;
77
className: string;
88
}
99

0 commit comments

Comments
 (0)