solidjs-community / solidjs-community/solid-primitives

Add an option to `createContextProvider` to throw an error instead of using a fallback in @solid-primitives/context

Open
#894 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
1.6k
Forks
162
Avg merge
19h 40m
Merged PRs (30d)
8

Description

Describe The Problem To Be Solved

Right now, if I want to use createContextProvider but maintain a strict "fail-fast" pattern (where it throws an error if used outside its provider). I either have to accept the T | undefined return type and manually wrap it with a null check, or I have to pass a dummy fallback object just to satisfy TypeScript, which actively hides the fact that the provider is missing. Since strict context is super common in Solid, support this would be a good idea.

Suggest A Solution

It would be awesome if the primitive natively supported strict mode. Maybe the second argument could be updated to accept a config object instead of just the fallback value, something like { fallback?: {...}, throws: ... }. The throws property could accept either a string for a standard error message, or even better, an Error class in case developers want to throw their own custom errors.

The ultimate goal is that the generated hook would automatically throw the error if the context is undefined, and the TypeScript return type would be strictly T without needing any extra wrapper hooks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the createContextProvider entry point and inspect its current fallback argument and generated hook return type. Compare the proposed config and error behavior, then cover missing-provider and fallback cases. Done means strict mode throws when the provider is missing, returns T in TypeScript, and preserves existing fallback behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.