Skip to content

Commit

Permalink
Add type parameter for key to createContext() (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani committed Feb 2, 2023
1 parent 4d69843 commit 61ce814
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-apricots-pay.md
@@ -0,0 +1,5 @@
---
'@lit-labs/context': patch
---

Add type parameter for key to createContext()
6 changes: 3 additions & 3 deletions packages/labs/context/src/lib/create-context.ts
Expand Up @@ -49,8 +49,8 @@ export type ContextType<Key extends Context<unknown, unknown>> =
*
* @param key a context key value
* @template ValueType the type of value that can be provided by this context.
* @returns the context key value with the correct type
* @returns the context key value cast to `Context<K, ValueType>`
*/
export function createContext<ValueType>(key: unknown) {
return key as Context<typeof key, ValueType>;
export function createContext<ValueType, K = unknown>(key: K) {
return key as Context<K, ValueType>;
}

0 comments on commit 61ce814

Please sign in to comment.