facebook / facebook/relay

[useFragment] Using two fragments inside component result in unknown or {} type

Open
#4,505 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

# useFragment

Hello, while I'm using two `useFragment` inside my component, the data coming from the second call gets either `unknown` or `{}` with Typescript:

E.g:

```typescript
const data1 = useFragment(FirstFragment, props.queryRef);

const person = useFragment(PersonFragment, data1.person);
```

I'm spreading the `PersonFragment` inside the `FirstFragment`, I checked for the types created by relay and Indeed they show the right definition for it, but for some reason, either Typescript/VS-Code isn't able to infer the type here.

Contributor guide

Open the contributing guide

Research direction

Start with the generated TypeScript definitions for FirstFragment and PersonFragment and the two-call useFragment example in the issue. Reproduce the inference result in VS Code or TypeScript, then trace why data1.person becomes unknown or {}. Done means the second useFragment receives and exposes the expected Person type.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.