Everything seems to be working well on Codepen, even without using window
. It's surprising because I'm used to having to use window.x
if ( 'Sanitizer' in window ) {
console.log( 'sani', 'Sanitizer' in window );
}
const c = new Sanitizer();
console.log( c );
const sa = ( window as any ).Sanitizer;
console.log( 'sa', sa );
I have everything set up and the works
perfectly. I've tried every possible way, but my compiled script doesn't seem to recognize the Sanitizer API. I've tried calling it in various ways, but nothing seems to work. Do I need to configure something in the tsconfig
? What's happening?
export {};
declare global {
interface Window {
works: inlineScriptJSON;
Sanitizer?: any;
}
}
console.log(
'window.Sanitizer',
window.Sanitizer,
// 'new window.Sanitizer()',
// new window.Sanitizer()
);
window.Sanitizer
is showing as undefined
.
new window.Sanitizer()
is giving this error:
Uncaught TypeError: window.Sanitizer is not a constructor
In my tsconfig.base.json
, the values under "lib" are underlined and it mentions that they are not acceptable options. I know this is new, but it works in Codepen, so what's different?
{
/* https://github.com/WordPress/gutenberg/blob/trunk/tsconfig.base.json */
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"allowSyntheticDefaultImports": true, // to make it compatible with babel
"jsx": "preserve",
"target": "esnext",
"module": "esnext",
"lib": [
"esnext",
"DOM",
"DOM.Iterable",
"DOM.Sanitizer",
"Sanitizer",
],
"declaration": true,
"declarationMap": true,
"composite": true,
"emitDeclarationOnly": true,
"isolatedModules": true,
/* Strict Type-Checking Options */
"strict": true,
/* Additional Checks */
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"importsNotUsedAsValues": "error",
/* Module Resolution Options */
"moduleResolution": "node", // because of webpack
/* This needs to be false so our types are possible to consume without setting this */
"esModuleInterop": false,
"resolveJsonModule": true,
"typeRoots": [ "./node_modules/@types" ],
"types": [],
/* nico */
"strictNullChecks": true,
"noImplicitAny": false,
"removeComments": true,
"allowUnreachableCode": false,
"sourceMap": true,
},
"exclude": [
"**/build/**",
"**/test/**"
],
}