Skip to content

fix(profiling): ts fails to infer | null#43762

Merged
JonasBa merged 1 commit into
masterfrom
jb/fix/project-slug-error
Jan 26, 2023
Merged

fix(profiling): ts fails to infer | null#43762
JonasBa merged 1 commit into
masterfrom
jb/fix/project-slug-error

Conversation

@JonasBa

@JonasBa JonasBa commented Jan 26, 2023

Copy link
Copy Markdown
Contributor

It seems TS fails to infer Project|null return type which caused a runtime error when we attempted to access project.slug property on null

CleanShot 2023-01-26 at 16 57 13@2x

@JonasBa JonasBa merged commit 1eec520 into master Jan 26, 2023
@JonasBa JonasBa deleted the jb/fix/project-slug-error branch January 26, 2023 23:02
export function useCurrentProjectFromRouteParam(): Project | null {
const params = useParams();
const projects = useProjects({limit: 1, slugs: [params?.projectId]});
return projects.projects?.[0] ?? null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this fail to infer?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because we don't have noUncheckedIndexedAccess, so it thinks the type will ALWAYS be Project.

mikejihbe pushed a commit that referenced this pull request Feb 6, 2023
It seems TS fails to infer Project|null return type which caused a
runtime error when we attempted to access project.slug property on null

<img width="463" alt="CleanShot 2023-01-26 at 16 57 13@2x"
src="https://user-images.githubusercontent.com/9317857/214966041-7e142dee-149f-46d5-9f3f-bc66476aef01.png">
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants