I was using SvelteKit without the amazing "strict": true in tsconfig.json until today.
I have this code generated (with codegen) from a Graphql schema that I cannot change:
export type PlayerListQuery = {
__typename?: "Query";
playerList: {
__typename?: "PlayerConnection";
edges?: Array<{
__typename?: "PlayerEdge";
cursor: any;
node?: {
__typename?: "Player";
name?: string | null;
age?: number | null;
id: string;
} | null;
} | null> | null;
pageInfo: {
__typename?: "PageInfo";
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor?: any | null;
endCursor?: any | null;
};
};
};
which comes from this:
type PlayerConnection {
totalCount: Int!
pageInfo: PageInfo!
edges: [PlayerEdge]
}
type PlayerEdge {
cursor: Cursor!
node: Player
}
and I'm using it like this in Svelte:
{#each $store.data.playerList.edges || [] as { cursor, node } (cursor)}
{node?.name || "No name"}
<br>
{node?.age || "No age"}
{:else}
Empty array!
{/each}
Now with the strict option the error is:
(parameter) cursor: any
Property 'cursor' does not exist on type '{ __typename?: "PlayerEdge" | undefined; cursor: any; node?: { __typename?: "Player" | undefined; name?: string | null | undefined; ... more ...; | undefined; } | null | undefined; } | null'.ts(2339)
both for cursor and node because it's right, they can be null or undefined.
What do you suggest to fix this?