diff --git a/package.json b/package.json index 4aa098952..d73933461 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "@types/storybook__addon-actions": "^3.4.2", "@types/storybook__addon-knobs": "^5.0.0", "@types/storybook__react": "^4.0.1", + "@types/uuid": "^3.4.4", "@typescript-eslint/eslint-plugin": "^1.5.0", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.1", diff --git a/src/scripts/util.js b/src/scripts/util.ts similarity index 74% rename from src/scripts/util.js rename to src/scripts/util.ts index 49a323d2d..b8dee46e7 100644 --- a/src/scripts/util.js +++ b/src/scripts/util.ts @@ -1,5 +1,4 @@ import createUUID from 'uuid'; -import { updateScroll } from 'react-relative-portal'; export const uuid = process.env.NODE_ENV === 'test' ? () => '$uuid$' : createUUID; @@ -11,7 +10,7 @@ export const getToday = let assetRoot = '/assets'; -export function setAssetRoot(path) { +export function setAssetRoot(path: string) { assetRoot = path; } @@ -19,13 +18,12 @@ export function getAssetRoot() { return assetRoot; } -export function registerStyle(styleName, rules) { +export function registerStyle(styleName: string, rules: string[][]) { const styleId = `react-slds-cssfix-${styleName}`; - let style = document.getElementById(styleId); - if (style) { + if (document.getElementById(styleId)) { return; } - style = document.createElement('style'); + const style = document.createElement('style'); style.id = styleId; style.appendChild(document.createTextNode('')); document.documentElement.appendChild(style); @@ -34,11 +32,11 @@ export function registerStyle(styleName, rules) { let selectors = ruleSet; selectors = selectors.concat(selectors.map((s) => `.slds ${s}`)); const rule = `${selectors.join(', ')} ${declaration}`; - style.sheet.insertRule(rule, 0); + (style.sheet as CSSStyleSheet).insertRule(rule, 0); } } -export function isElInChildren(rootEl, targetEl) { +export function isElInChildren(rootEl: any, targetEl: any) { /* eslint-disable no-param-reassign */ while (targetEl && targetEl !== rootEl) { targetEl = targetEl.parentNode; @@ -47,7 +45,7 @@ export function isElInChildren(rootEl, targetEl) { return !!targetEl; } -export function offset(el) { +export function offset(el: HTMLElement) { const rect = el.getBoundingClientRect(); return { @@ -56,9 +54,10 @@ export function offset(el) { }; } -export function cleanProps(props, propTypes) { +export function cleanProps(props: object, propTypes: object) { const newProps = props; Object.keys(propTypes).forEach((key) => { + // @ts-ignore delete newProps[key]; }); return newProps; @@ -71,5 +70,4 @@ export default { isElInChildren, offset, cleanProps, - updateScroll, }; diff --git a/yarn.lock b/yarn.lock index 9cf52f4d7..162ebcb3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1840,6 +1840,13 @@ resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e" integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ== +"@types/uuid@^3.4.4": + version "3.4.4" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.4.4.tgz#7af69360fa65ef0decb41fd150bf4ca5c0cefdf5" + integrity sha512-tPIgT0GUmdJQNSHxp0X2jnpQfBSTfGxUMc/2CXBU2mnyTFVYVa2ojpoQ74w0U2yn2vw3jnC640+77lkFFpdVDw== + dependencies: + "@types/node" "*" + "@types/vfile-message@*": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/vfile-message/-/vfile-message-1.0.1.tgz#e1e9895cc6b36c462d4244e64e6d0b6eaf65355a"