mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
typing_status: Mark recipient array as read-only for Flow.
This type means that code consuming this value promises not to mutate it. It's useful partly for the sake of simply controlling mutation, so that arrays can be passed around without making defensive copies; and partly because it makes the type covariant in the elements, rather than invariant. That is, if a function takes a plain Array<number | null>, then you can't pass it an Array<number>, because it might add a `null` to it. But if it takes $ReadOnlyArray<number | null>, then you can. In general, Array<S> <: $ReadOnlyArray<S> <: $ReadOnlyArray<T> for any S <: T, where `<:` means "is a subtype of". Marking this type as read-only means we can pass in a read-only array without adding a fixme (equivalent to a mypy type-ignore) to locally disable the type-checker, nor a redundant defensive copy.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
type RecipientUserIds = number[];
|
||||
type RecipientUserIds = $ReadOnlyArray<number>;
|
||||
|
||||
type Worker = {|
|
||||
get_current_time: () => number, // as ms since epoch
|
||||
|
||||
Reference in New Issue
Block a user