-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Which package(s) are affected?
Context (@lit-labs/context)
Description
The code is this:
@provide({ context: studentContext })
@property({ type: Object })
student?: Student;The typing error I get with this:
Argument of type 'Root' is not assignable to parameter of type 'ReactiveElement & Record<"student", Student>'.
Type 'Root' is not assignable to type 'Record<"student", Student>'.
Types of property 'student' are incompatible.
Type 'Student | undefined' is not assignable to type 'Student'.
Type 'undefined' is not assignable to type 'Student'.ts(2345)
If I make the property not optional (so remove the question mark), then I get this typing error:
Property 'student' has no initializer and is not definitely assigned in the constructor.ts(2564)
"Damned if I do, damned if I don't"....
Reproduction
Workaround
I've tried this, to no avail: export const studentContext = createContext<Student | undefined>('student');
If I do the above, then I do get a different typing error:
Argument of type 'Root' is not assignable to parameter of type 'ReactiveElement & Record<"student", Student | undefined>'.
Type 'Root' is not assignable to type 'Record<"student", Student | undefined>'.
Property 'student' is optional in type 'Root' but required in type 'Record<"student", Student | undefined>'.ts(2345)
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
"@lit-labs/context": "^0.2.0",
Browser/OS/Node environment
"typescript": "^4.9.5" with "strict": true, in tsconfig.json
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
✅ Done