Skip to content

Passing an immutable value Immutable<T> to a function that expects a mutable parameter T #77

Answered by unadlib
alexamy asked this question in Q&A

You must be logged in to vote

hi @alexamy,

Immutable is a strict immutable generic type that primarily uses TypeScript's readonly 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

You must be logged in to vote
0 replies
Answer selected by alexamy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants