Skip to content

feat(context): improve createContext type definitions#3783

Open
isBatak wants to merge 6 commits intochakra-ui:mainfrom
isBatak:improve-create-context-type
Open

feat(context): improve createContext type definitions#3783
isBatak wants to merge 6 commits intochakra-ui:mainfrom
isBatak:improve-create-context-type

Conversation

@isBatak
Copy link
Contributor

@isBatak isBatak commented Feb 12, 2026

Closes #

📝 Description

Fix the return type of createContext when strict is set to false so that the generated hook correctly includes undefined in its return type.

Currently, when using createContext({ strict: false }), the return type of useContext() does not include undefined, even though the context can be undefined at runtime.

⛳️ Current behavior (updates)

Even though context can be undefined, its type does not include undefined. As a result, when using it conditionally:

disabled={context?.disabled}

ESLint auto-fix removes the optional chaining (?.) because the type system indicates that context is always defined.

🚀 New behavior

When strict is false, the return type of the generated hook becomes:

T | undefined

This correctly reflects runtime behavior and allows safe conditional usage like:

disabled={context?.disabled}

TypeScript and ESLint will no longer incorrectly treat the value as always defined.

💣 Is this a breaking change (Yes/No):

No.

This change only improves the TypeScript return type to better reflect the existing runtime behavior when strict is false.

📝 Additional Information

@vercel
Copy link

vercel bot commented Feb 12, 2026

@isBatak is attempting to deploy a commit to the Chakra UI Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments