-
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 well
const f = (element: HTMLElement) => {};
const el: Immutable<HTMLElement> = document.body;
// TypeScript error:
// The type 'readonly ImmutableObject<CSSStyleSheet>[]' is 'readonly' and cannot be assigned to the mutable type 'CSSStyleSheet[]'.
f(el); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hi @alexamy,
For stricter immutability, we do not recommend such compatibility. As a workaround, you could also do it this way:
|
Beta Was this translation helpful? Give feedback.
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: