sagnik Posted February 27, 2023 Posted February 27, 2023 Quote src/js/SGNUIKit.loader.js:29:1 - error TS9005: Declaration emit for this file requires using private name 'SGNUKConfig'. An explicit type annotation may unblock declaration emit. 29 const forEach = (obj, callback) => { ~~~~~ Here's the part of the code: /** * Performs the specified action for each element in an object. * * @param {Object} obj * @param {(value:any, key:string)=>void} callback A function that accepts up to three arguments. forEach calls the <b><i>callback</i></b> function one time for each element in the object. */ const forEach = (obj, callback) => { let value; //context = context || this; //apply the function to 'this' by default for(const key in obj) { if(key !== 'length' && obj.hasOwnProperty(key)) { //to rule out inherited properties value = obj[key]; if(typeof callback === 'function') callback(value, key); } } } /** * Appends new elements to the end of an object, and returns the new length of the object. * @param {Object} obj * @param {...any} items New elements to add to the object. */ const push = (obj, ...items) => { let k = obj.length || 0; items.forEach((value) => { obj[k] = value; k++; obj.length = k; }); } const SGNUIKit = { isReady: false, isInit: false, isPreloaderHeld: false, configs: { 'urls': { 'api': { 'geonames': 'https://secure.geonames.org/', 'osm': 'https://nominatim.openstreetmap.org/' }, }, 'api': { 'geonames': '' //username }, 'geocoding': { 'defaultAPI': 'osm' } }, components: {}, onChangeListener: {}, onInitListener: {}, onReadyListener: {}, callCounts: { 'init': 0, 'ready': 0, 'config': 0, 'component': 0, 'holdPreloader': 0, }, /** * This callback is called when a component is loaded/removed or the status of readiness is changed. * * @callback SGNUIKitChangeCallback * @param {string} state The name of the state which is changed. * @param {boolean|JSON} value The value of the state which is changed. * @param {JSON} components The <b><i>JSON</i></b> object of loaded <b>SGNUIKit</b> components, or an empty <b><i>JSON</i></b> object if no components loaded. */ /** * This callback is called when <b>SGNUIKit</b> is ready. * * @callback SGNUIKitReadyCallback * @param {boolean} isReady the status of readiness of <b>SGNUIKit</b>. */ /** * Add a loaded <b>SGNUIKit</b> component. * * @param {{}} config The <b><i>JSON</i></b> object of the <b>SGNUIKit</b> configuration options. */ set config(config) { if(config !== undefined && config !== null && config !== "") { this.configs = new SGNUKConfig(config); this.callCounts.config++; forEach(this.onChangeListener, (listener) => listener("config", config, this.configs)); } }, /** * Get the list of loaded <b>SGNUIKit</b> components. * * @return {Object} The <b><i>JSON</i></b> object of loaded <b>SGNUIKit</b> components, or an empty <b><i>JSON</i></b> object if no components loaded. */ get config() { return this.configs; }, /** * Add a loaded <b>SGNUIKit</b> component. * * @param {{}} value The <b><i>JSON</i></b> object of the loaded <b>SGNUIKit</b> component. */ set component(value) { if(value !== undefined && value !== null && value !== "") { Object.assign(this.components, value); this.callCounts.component++; forEach(this.onChangeListener, (listener) => listener("components", value, this.components)); //this.onChangeListener.forEach((listener) => listener("components", value, this.components)); } }, /** * Get the list of loaded <b>SGNUIKit</b> components. * * @return {object} The <b><i>JSON</i></b> object of loaded <b>SGNUIKit</b> components, or an empty <b><i>JSON</i></b> object if no components loaded. */ get component() { return this.components; }, /** * Check if a <b>SGNUIKit</b> component is loaded. * * @param {string|number} id The <i>ID</i> of the <b>SGNUIKit</b> component to check. */ isComponentLoaded: function(id) { return this.components.hasOwnProperty(id); }, /** * Set the status of readiness of <b>SGNUIKit</b>. * * @param {boolean} isInit The the status of readiness of <b>SGNUIKit</b>. */ set init(isInit) { this.isInit = isInit; this.callCounts.init++; forEach(this.onChangeListener, (listener) => listener("init", this.isInit)); if(isInit) forEach(this.onInitListener, (listener) => listener(isInit)); }, /** * Get the status of readiness of <b>SGNUIKit</b>. * * @return {boolean} <b><i>TRUE</i></b> if <b>SGNUIKit</b> is ready, <b><i>FALSE</i></b> otherwise. */ get init() { return this.isInit; }, /** * Set the status of readiness of <b>SGNUIKit</b>. * * @param {boolean} isReady The the status of readiness of <b>SGNUIKit</b>. */ set ready(isReady) { this.isReady = isReady; this.callCounts.ready++; forEach(this.onChangeListener, (listener) => listener("ready", this.isReady)); //this.onChangeListener.forEach((listener) => listener("ready", this.isReady)); if(isReady) forEach(this.onReadyListener, (listener) => listener(isReady)); //this.onReadyListener.forEach((listener) => listener(isReady)); }, /** * Get the status of readiness of <b>SGNUIKit</b>. * * @return {boolean} <b><i>TRUE</i></b> if <b>SGNUIKit</b> is ready, <b><i>FALSE</i></b> otherwise. */ get ready() { return this.isReady; }, /** * Hold the <b>SGNUIKit</b> preloader even after <b>SGNUIKit</b> has finished loading the components. * * @param {boolean} hold The the status of readiness of <b>SGNUIKit</b>. */ set holdPreloader(hold) { this.isPreloaderHeld = hold; this.callCounts.holdPreloader++; forEach(this.onChangeListener, (listener) => listener("holdPreloader", this.isPreloaderHeld)); //this.onChangeListener.forEach((listener) => listener("holdPreloader", this.isPreloaderHeld)); }, /** * Get the status of readiness of <b>SGNUIKit</b>. * * @return {boolean} <b><i>TRUE</i></b> if <b>SGNUIKit</b> is ready, <b><i>FALSE</i></b> otherwise. */ get holdPreloader() { return this.isPreloaderHeld; }, /** * Set the handler for <b>SGNUIKit</b> <b><i>OnChange</i></b> event, which will be triggered when a component is loaded/removed or the status of readiness is changed. * * @param {SGNUIKitChangeCallback}listener * @param {string|number}[id=undefined] */ setOnChangeListener: function(listener, id) { if(typeof id !== 'string' || $.isNumeric(id)) this.onChangeListener[id] = listener; else push(this.onChangeListener, listener); }, /** * Set the handler for <b>SGNUIKit</b> <b><i>OnReady</i></b> event, which will be triggered when the <b>SGNUIKit</b> is ready. * * @param {SGNUIKitReadyCallback}listener * @param {string|number}[id=undefined] */ setOnInitListener: function(listener, id) { if(typeof id !== 'string' || $.isNumeric(id)) this.onInitListener[id] = listener; else push(this.onInitListener, listener); if(this.init) forEach(this.onInitListener, (listener) => listener(this.isInit)); }, /** * Set the handler for <b>SGNUIKit</b> <b><i>OnReady</i></b> event, which will be triggered when the <b>SGNUIKit</b> is ready. * * @param {SGNUIKitReadyCallback}listener * @param {string|number}[id=undefined] */ setOnReadyListener: function(listener, id) { if(typeof id !== 'string' || $.isNumeric(id)) this.onReadyListener[id] = listener; else push(this.onReadyListener, listener); if(this.ready) forEach(this.onReadyListener, (listener) => listener(this.isReady)); //this.onReadyListener.forEach((listener) => listener(this.ready)); }, }; window.SGNUIKit = SGNUIKit; if(typeof jQuery === 'undefined') { // EMBED JQUERY } /*** * @return {SGNUKConfig} */ const SGNUKConfig = function(config) { const plugin = this; const _defaults = { 'urls': { 'api': { 'geonames': 'https://secure.geonames.org/', 'osm': 'https://nominatim.openstreetmap.org/' }, } } plugin.config = { 'api': { 'geonames': undefined //username }, 'geocoding': { 'defaultAPI': 'osm' } } const init = () => { plugin.config = Object.assign(plugin.config, config); plugin.config = Object.assign(plugin.config, _defaults); } init(); return plugin; }; ((callback) => { const head = document.head || document.getElementsByTagName("head")[0], style = document.createElement("style"); const currentScript = document.currentScript || document.querySelector("script[src*=\"SGNUIKit.loader.js\"]"); let preloader = `\t\t\t<div class="preloader">\n`; //OTHER CODES HERE head.appendChild(style); preloaderElem.innerHTML = preloader; window.onload = function() { document.body.classList.add("has-preloader"); document.body.insertBefore(preloaderElem, document.body.firstChild); if(typeof callback === 'function') callback(); }; })(() => { (async precallback => { const title = document.title; if(title !== undefined) document.title = "Loading..."; if(window.jQuery) $.holdReady(true); //OTHER CODES HERE async function finishLoad() { progress = (filestoload > 0) ? Math.round((filesloaded * 100) / filestoload) : 100; await new Promise(resolve => { if(filesloaded >= filestoload) { resolve(); } }).then(function() { document.querySelector('head > title').innerHTML = title; if(typeof precallback === "function" && progress === 100) precallback(); }); } })(function() { (async callback => { (() => { const startLoad = new Promise(async function(resolve) { await loadStyle(0); await loadScript(0); if(loaded === total) resolve(); }); startLoad.then(() => { finishLoad(); }); })(); async function finishLoad() { const progress = Math.round((loaded * 100) / total); await new Promise(resolve => { if(loaded === total) { resolve(); } }).then(function() { if(typeof callback === "function") callback(loaded, total, progress); }); } })((loaded, total, progress) => { if(progress === 100) { SGNUIKit.init = true; const styles = document.querySelector("style#sgn-uikit-styles"); const left = document.querySelector("style[data-cke=\"true\"]"); if(left !== null) left.parentNode.removeChild(left); if(styles !== null) styles.parentNode.removeChild(styles); $.holdReady(false); jQuery.ready(); } }); }); (() => { SGNUIKit.setOnChangeListener((prop, value) => { if(prop === 'holdPreloader') { if(SGNUIKit.init && !value) { finalize(true); } } else { if(prop === 'init' && value) { finalize(false); } } }, 'sgn-uk-prop-change-listener'); })(); }); tsconfig.json { "include": [ //"./src/addons/*.js", "./src/js/*.js" ], "compilerOptions": { "outDir": "./dist/lib", "declarationDir": "dist/types", "target": "ES6", "module": "ES6", "moduleResolution": "Classic", "strictPropertyInitialization": false, "esModuleInterop": true, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, "allowSyntheticDefaultImports": true, "removeComments": true, "allowJs": true, "checkJs": true, "strict": false, "skipLibCheck": true, "allowUmdGlobalAccess": true, "alwaysStrict": true, "useDefineForClassFields": true, // Generate d.ts files "declaration": true, // only output d.ts files "emitDeclarationOnly": true, "declarationMap": true, //"types": [], "typeRoots": [ "./src/types" ] }, "exclude": [ "node_modules", "./node_modules", "./node_modules/*", "./node_modules/@types/node/index.d.ts", ".backup", ".github", "build", "demos", "dist", "docs", "release" ] }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now