|
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); |
Answered by
unadlib
Feb 5, 2025
Replies: 1 comment
|
hi @alexamy,
For stricter immutability, we do not recommend such compatibility. As a workaround, you could also do it this way: |
0 replies
Answer selected by
alexamy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi @alexamy,
Immutableis a strict immutable generic type that primarily uses TypeScript'sreadonlykeyword 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: