Merge pull request #32000 from vrana/master

Add trusted-types
This commit is contained in:
Daniel Rosenwasser
2019-01-18 17:18:10 -08:00
committed by GitHub
4 changed files with 83 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
// Type definitions for trusted-types 1.0
// Project: https://github.com/WICG/trusted-types
// Definitions by: Jakub Vrana <https://github.com/vrana>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class TrustedHTML {
private readonly _TrustedHTMLBrand: true; // To prevent structural typing.
}
declare class TrustedScript {
private readonly _TrustedScriptBrand: true; // To prevent structural typing.
}
declare class TrustedScriptURL {
private readonly _TrustedScriptURLBrand: true; // To prevent structural typing.
}
declare class TrustedURL {
private readonly _TrustedURLBrand: true; // To prevent structural typing.
}
declare class TrustedTypePolicy {
createHTML(s: string): TrustedHTML;
createScript(s: string): TrustedScript;
createScriptURL(s: string): TrustedScriptURL;
createURL(s: string): TrustedURL;
}
interface TrustedTypeInnerPolicy {
createHTML(s: string): string;
createScript(s: string): string;
createScriptURL(s: string): string;
createURL(s: string): string;
}
declare class TrustedTypePolicyFactory {
createPolicy(name: string, policy: TrustedTypeInnerPolicy, expose?: boolean): TrustedTypePolicy;
getExposedPolicy(name: string): TrustedTypePolicy;
getPolicyNames(): string[];
}
declare const TrustedTypes: TrustedTypePolicyFactory;
@@ -0,0 +1,17 @@
const policy = {
createHTML: (s: string) => s,
createScript: (s: string) => s,
createScriptURL: (s: string) => s,
createURL: (s: string) => s,
};
TrustedTypes.getPolicyNames();
TrustedTypes.createPolicy('default', policy, true);
TrustedTypes.getExposedPolicy('default');
const trustedTypes = TrustedTypes.createPolicy('test', policy);
trustedTypes.createHTML('') instanceof TrustedHTML;
trustedTypes.createScript('') instanceof TrustedScript;
trustedTypes.createScriptURL('') instanceof TrustedScriptURL;
trustedTypes.createURL('') instanceof TrustedURL;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"trusted-types-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }