- Notifications
You must be signed in to change notification settings - Fork23
-
I frequently pass values of type As a workaround, I avoid the issue by passing problematic types together with
// Expecting to pass `Immutable<HTMLElement>` as wellconstf=(element:HTMLElement)=>{};constel:Immutable<HTMLElement>=document.body;// TypeScript error:// The type 'readonly ImmutableObject<CSSStyleSheet>[]' is 'readonly' and cannot be assigned to the mutable type 'CSSStyleSheet[]'.f(el); |
BetaWas this translation helpful?Give feedback.
All reactions
hi@alexamy,
Immutable is a strict immutable generic type that primarily uses TypeScript'sreadonly keyword to ensure properties are immutable, and it traverses all deep nested properties.
For stricter immutability, we do not recommend such compatibility.
As a workaround, you could also do it this way:
const f = (element: HTMLElement) => {};const el: Immutable<HTMLElement> = document.body;f(el as HTMLElement);Replies: 1 comment
-
hi@alexamy,
For stricter immutability, we do not recommend such compatibility. As a workaround, you could also do it this way: |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1