Skip to content

Commit f516370

Browse files
alan-agius4AndrewKushnir
authored andcommitted
fix(core): use mutable ResponseInit type for RESPONSE_INIT token
The `RESPONSE_INIT` token previously used `ResponseInit`. However, `@types/node` (and `undici`) definitions for `ResponseInit` mark properties as `readonly`, which differs from the standard DOM `ResponseInit`. This commit introduces a `ResponseInit` type that explicitly removes `readonly` modifiers to ensure compatibility and allow for mutable options. This type is now used by the `RESPONSE_INIT` token and is exported from `@angular/core`.
1 parent 9fa77af commit f516370

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

goldens/public-api/core/index.api.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,13 @@ export type ResourceStreamItem<T> = {
16791679
};
16801680

16811681
// @public
1682-
export const RESPONSE_INIT: InjectionToken<ResponseInit | null>;
1682+
export const RESPONSE_INIT: InjectionToken<ResponseInit_2 | null>;
1683+
1684+
// @public
1685+
type ResponseInit_2 = {
1686+
-readonly [P in keyof globalThis.ResponseInit]: globalThis.ResponseInit[P];
1687+
};
1688+
export { ResponseInit_2 as ResponseInit }
16831689

16841690
// @public
16851691
export function runInInjectionContext<ReturnT>(injector: Injector, fn: () => ReturnT): ReturnT;

packages/core/src/application/platform_tokens.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export const REQUEST = new InjectionToken<Request | null>(
3636
},
3737
);
3838

39+
/**
40+
* Type that represents the initialization options for a response.
41+
*
42+
* @publicApi
43+
*/
44+
export type ResponseInit = {
45+
// This is needed as `@types/node` and Undici marks all these properties as readonly. This is not the case in lib.dom.d.ts
46+
-readonly [P in keyof globalThis.ResponseInit]: globalThis.ResponseInit[P];
47+
};
48+
3949
/**
4050
* Injection token for response initialization options.
4151
*

packages/core/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export {Binding, inputBinding, outputBinding, twoWayBinding} from './render3/dyn
116116
export {ApplicationConfig, mergeApplicationConfig} from './application/application_config';
117117
export {makeStateKey, StateKey, TransferState} from './transfer_state';
118118
export {booleanAttribute, numberAttribute} from './util/coercion';
119-
export {REQUEST, REQUEST_CONTEXT, RESPONSE_INIT} from './application/platform_tokens';
119+
export {REQUEST, REQUEST_CONTEXT, RESPONSE_INIT, ResponseInit} from './application/platform_tokens';
120120
export {DOCUMENT} from './document';
121121
export {provideNgReflectAttributes} from './ng_reflect';
122122
export {

0 commit comments

Comments
 (0)