Skip to content

Commit

Permalink
Unable 'strict' checks for TSC
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Aug 8, 2023
1 parent 5073408 commit 94992ba
Show file tree
Hide file tree
Showing 32 changed files with 368 additions and 285 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ overrides:
'react/jsx-key': off
'react/no-string-refs': off
'@typescript-eslint/no-var-requires': off

# FIXME: blocked by improper type checking should be fixed
# after we switch TSC in strict mode
'@typescript-eslint/no-non-null-assertion': off
'@typescript-eslint/no-unnecessary-boolean-literal-compare': off
'@typescript-eslint/no-explicit-any': off
'@typescript-eslint/dot-notation': off
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/node": "18.15.5",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.10",
"@types/webpack-node-externals": "^3.0.0",
"@typescript-eslint/eslint-plugin": "5.30.7",
"@typescript-eslint/parser": "5.30.7",
"cspell": "6.2.3",
Expand Down
4 changes: 2 additions & 2 deletions scripts/serve-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function consoleError(msg: string) {

http
.createServer((request, response) => {
const url = new URL(request.url, 'file:');
const url = new URL(request.url!, 'file:');
let filePath = url.pathname;
if (filePath === '/') {
filePath = '/index.html';
}
filePath = path.join(options.directory, filePath);

const extname = String(path.extname(filePath)).toLowerCase();
const mimeTypes = {
const mimeTypes: { [ext: string]: string } = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
Expand Down
22 changes: 14 additions & 8 deletions src/components/GraphViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ interface GraphViewportProps {
typeGraph: TypeGraph | null;
displayOptions: VoyagerDisplayOptions;

selectedTypeID: string;
selectedEdgeID: string;
selectedTypeID: string | null;
selectedEdgeID: string | null;

onSelectNode: (id: string) => void;
onSelectNode: (id: string | null) => void;
onSelectEdge: (id: string) => void;
}

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

// Handle async graph rendering based on this example
// https://gist.github.com/bvaughn/982ab689a41097237f6e9860db7ca8d6
_currentTypeGraph = null;
_currentDisplayOptions = null;
_currentTypeGraph: TypeGraph | null = null;
_currentDisplayOptions: VoyagerDisplayOptions | null = null;

static getDerivedStateFromProps(props, state) {
static getDerivedStateFromProps(
props: GraphViewportProps,
state: GraphViewportState,
): GraphViewportState | null {
const { typeGraph, displayOptions } = props;

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

componentDidUpdate(prevProps, prevState) {
componentDidUpdate(
prevProps: GraphViewportProps,
prevState: GraphViewportState,
) {
const { svgViewport } = this.state;

if (svgViewport == null) {
Expand Down Expand Up @@ -150,7 +156,7 @@ export default class GraphViewport extends Component<
}
}

focusNode(id) {
focusNode(id: string) {
const { svgViewport } = this.state;
if (svgViewport) {
svgViewport.focusElement(id);
Expand Down
6 changes: 3 additions & 3 deletions src/components/IntrospectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ interface IntrospectionModalProps {

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

const [submitted, setSubmitted] = useState({
inputType: hasPresets ? InputType.Presets : InputType.SDL,
Expand Down Expand Up @@ -103,7 +103,7 @@ export function IntrospectionModal(props: IntrospectionModalProps) {
function handleSubmit() {
switch (inputType) {
case InputType.Presets:
onChange(buildClientSchema(presets[activePreset].data));
onChange(buildClientSchema(presets?.[activePreset].data));
break;
case InputType.Introspection:
// check for errors and check if valid
Expand Down
43 changes: 30 additions & 13 deletions src/components/Voyager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { GraphQLSchema } from 'graphql/type';
import { buildClientSchema, IntrospectionQuery } from 'graphql/utilities';
import {
Children,
type ReactElement,
type ReactNode,
useEffect,
useMemo,
Expand Down Expand Up @@ -52,7 +51,7 @@ export interface VoyagerProps {
}

export default function Voyager(props: VoyagerProps) {
const initialDisplayOptions: VoyagerDisplayOptions = useMemo(
const initialDisplayOptions = useMemo(
() => ({
rootType: undefined,
skipRelay: true,
Expand Down Expand Up @@ -83,10 +82,19 @@ export default function Voyager(props: VoyagerProps) {
return null;
}

const introspectionSchema =
introspectionResult.value instanceof GraphQLSchema
? introspectionResult.value
: buildClientSchema(introspectionResult.value.data);
let introspectionSchema;
if (introspectionResult.value instanceof GraphQLSchema) {
introspectionSchema = introspectionResult.value;
} else {
if (
introspectionResult.value.errors != null ||
introspectionResult.value.data == null
) {
// FIXME: display errors
return null;
}
introspectionSchema = buildClientSchema(introspectionResult.value.data);
}

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

const [selected, setSelected] = useState({ typeID: null, edgeID: null });
const [selected, setSelected] = useState<{
typeID: string | null;
edgeID: string | null;
}>({
typeID: null,
edgeID: null,
});

const {
allowToChangeSchema = false,
Expand All @@ -115,7 +129,7 @@ export default function Voyager(props: VoyagerProps) {
hideVoyagerLogo = true,
} = props;

const viewportRef = useRef(null);
const viewportRef = useRef<GraphViewport>(null);
useEffect(() => viewportRef.current?.resize(), [hideDocs]);

return (
Expand Down Expand Up @@ -143,7 +157,10 @@ export default function Voyager(props: VoyagerProps) {
function renderPanel() {
const children = Children.toArray(props.children);
const panelHeader = children.find(
(child: ReactElement) => child.type === Voyager.PanelHeader,
(child) =>
typeof child === 'object' &&
'type' in child &&
child.type === Voyager.PanelHeader,
);

return (
Expand All @@ -156,7 +173,7 @@ export default function Voyager(props: VoyagerProps) {
typeGraph={typeGraph}
selectedTypeID={selected.typeID}
selectedEdgeID={selected.edgeID}
onFocusNode={(id) => viewportRef.current.focusNode(id)}
onFocusNode={(id) => viewportRef.current?.focusNode(id)}
onSelectNode={handleSelectNode}
onSelectEdge={handleSelectEdge}
/>
Expand Down Expand Up @@ -210,7 +227,7 @@ export default function Voyager(props: VoyagerProps) {
);
}

function handleSelectNode(typeID: string) {
function handleSelectNode(typeID: string | null) {
setSelected((oldSelected) => {
if (typeID === oldSelected.typeID) {
return oldSelected;
Expand All @@ -219,9 +236,9 @@ export default function Voyager(props: VoyagerProps) {
});
}

function handleSelectEdge(edgeID: string) {
function handleSelectEdge(edgeID: string | null) {
setSelected((oldSelected) => {
if (edgeID === oldSelected.edgeID) {
if (edgeID === oldSelected.edgeID || edgeID == null) {
// deselect if click again
return { ...oldSelected, edgeID: null };
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/doc-explorer/Argument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import WrappedTypeName from './WrappedTypeName';

interface ArgumentProps {
arg: GraphQLArgument;
filter: string;
filter: string | null;
expanded: boolean;
onTypeLink: (type: GraphQLNamedType) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/doc-explorer/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './Description.css';
import Markdown from '../utils/Markdown';

interface DescriptionProps {
text?: string;
text: string | undefined | null;
className: string;
}

Expand Down
Loading

0 comments on commit 94992ba

Please sign in to comment.