Skip to content

Commit b6957da

Browse files
fix(http): make List and InnerList.items readonly, document ParameterMap naming
1 parent 9301b98 commit b6957da

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

http/structured_fields.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export type BareItem =
7171
/**
7272
* Parameters attached to an Item or Inner List.
7373
*
74+
* Named `ParameterMap` rather than RFC 9651's "Parameters" to avoid clashing
75+
* with TypeScript's built-in `Parameters<T>` utility type.
76+
*
7477
* Returned parameters are immutable. When building parameters for serialization,
7578
* you can pass a mutable `Map` as it is assignable to `ReadonlyMap`.
7679
*
@@ -97,17 +100,20 @@ export interface Item {
97100
*/
98101
export interface InnerList {
99102
/** The items in the inner list. */
100-
items: Item[];
103+
items: readonly Item[];
101104
/** Parameters associated with the inner list. */
102105
parameters: ParameterMap;
103106
}
104107

105108
/**
106109
* A List Structured Field value.
107110
*
111+
* Returned lists are immutable. When building lists for serialization,
112+
* you can pass a mutable array as it is assignable to `ReadonlyArray`.
113+
*
108114
* @see {@link https://www.rfc-editor.org/rfc/rfc9651#section-3.1}
109115
*/
110-
export type List = Array<Item | InnerList>;
116+
export type List = ReadonlyArray<Item | InnerList>;
111117

112118
/**
113119
* A Dictionary Structured Field value.
@@ -329,7 +335,7 @@ export function item(
329335
* ```
330336
*/
331337
export function innerList(
332-
items: Item[],
338+
items: readonly Item[],
333339
parameters?: Iterable<[string, BareItem]>,
334340
): InnerList {
335341
return { items, parameters: new Map(parameters) };
@@ -541,7 +547,7 @@ export function parseList(input: string): List {
541547
}
542548

543549
function parseListInternal(state: ParserState): List {
544-
const members: List = [];
550+
const members: (Item | InnerList)[] = [];
545551

546552
while (!isEof(state)) {
547553
const member = parseItemOrInnerList(state);

0 commit comments

Comments
 (0)