Skip to content

Commit 5d50e8a

Browse files
committed
Add type parameter for key to createContext()
1 parent 1d8a38e commit 5d50e8a

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

.changeset/happy-apricots-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lit-labs/context': patch
3+
---
4+
5+
Add type parameter for key to createContext()

packages/labs/context/src/lib/create-context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export type ContextType<Key extends Context<unknown, unknown>> =
4949
*
5050
* @param key a context key value
5151
* @template ValueType the type of value that can be provided by this context.
52-
* @returns the context key value with the correct type
52+
* @returns the context key value cast to `Context<K, ValueType>`
5353
*/
54-
export function createContext<ValueType>(key: unknown) {
55-
return key as Context<typeof key, ValueType>;
54+
export function createContext<ValueType, K = unknown>(key: K) {
55+
return key as Context<K, ValueType>;
5656
}

0 commit comments

Comments
 (0)