build: replace @types/trusted-types dep with minimal type defs (#39211)
The @types/trusted-types type definitions are currently imported in types.d.ts, which causes them to eventually be imported in core.d.ts. This forces anyone compiling against @angular/core to provide the @types/trusted-types package in their compilation unit, which we don't want. To address this, get rid of the @types/trusted-types and instead import a minimal version of the Trusted Types type definitions directly into Angular's codebase. Update the existing references to Trusted Types to point to the new definitions. PR Close #39211
This commit is contained in:
50
packages/core/src/util/security/trusted_type_defs.ts
Normal file
50
packages/core/src/util/security/trusted_type_defs.ts
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
* While Angular only uses Trusted Types internally for the time being,
|
||||
* references to Trusted Types could leak into our core.d.ts, which would force
|
||||
* anyone compiling against @angular/core to provide the @types/trusted-types
|
||||
* package in their compilation unit.
|
||||
*
|
||||
* Until https://github.com/microsoft/TypeScript/issues/30024 is resolved, we
|
||||
* will keep Angular's public API surface free of references to Trusted Types.
|
||||
* For internal and semi-private APIs that need to reference Trusted Types, the
|
||||
* minimal type definitions for the Trusted Types API provided by this module
|
||||
* should be used instead.
|
||||
*
|
||||
* Adapted from
|
||||
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/trusted-types/index.d.ts
|
||||
* but restricted to the API surface used within Angular.
|
||||
*/
|
||||
|
||||
export type TrustedHTML = {
|
||||
__brand__: 'TrustedHTML'
|
||||
};
|
||||
export type TrustedScript = {
|
||||
__brand__: 'TrustedScript'
|
||||
};
|
||||
export type TrustedScriptURL = {
|
||||
__brand__: 'TrustedScriptURL'
|
||||
};
|
||||
|
||||
export interface TrustedTypePolicyFactory {
|
||||
createPolicy(policyName: string, policyOptions: {
|
||||
createHTML?: (input: string) => string,
|
||||
createScript?: (input: string) => string,
|
||||
createScriptURL?: (input: string) => string,
|
||||
}): TrustedTypePolicy;
|
||||
getAttributeType(tagName: string, attribute: string): string|null;
|
||||
}
|
||||
|
||||
export interface TrustedTypePolicy {
|
||||
createHTML(input: string): TrustedHTML;
|
||||
createScript(input: string): TrustedScript;
|
||||
createScriptURL(input: string): TrustedScriptURL;
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
import {global} from '../global';
|
||||
import {TrustedHTML, TrustedScript, TrustedScriptURL, TrustedTypePolicy, TrustedTypePolicyFactory} from './trusted_type_defs';
|
||||
|
||||
/**
|
||||
* The Trusted Types policy, or null if Trusted Types are not
|
||||
|
Reference in New Issue
Block a user