Skip to content

Commit ddf5135

Browse files
csvnjustinfagnani
authored andcommitted
Move global types to project d.ts file (lit#567)
* Avoid using TS skipLibCheck The errors from 'source-map' occurs due to `web-component-tester`. Since the only `@types` required in this project is mocha and chai, we can solve lib errors by excluding all others. * Use a d.ts file for global type adjustments
1 parent 80fac2e commit ddf5135

6 files changed

+30
-28
lines changed

src/env.d.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
interface ShadyCSS {
2+
nativeCss: boolean;
3+
nativeShadow: boolean;
4+
styleElement(host: Element, overrideProps?: {[key: string]: string}): void;
5+
prepareTemplateDom(template: Element, elementName: string): void;
6+
prepareTemplateStyles(
7+
template: Element, elementName: string, typeExtension?: string): void;
8+
}
9+
10+
interface ShadyDOM {
11+
inUse: boolean;
12+
}
13+
14+
interface Window {
15+
ShadyCSS?: ShadyCSS;
16+
ShadyDOM?: ShadyDOM;
17+
}
18+
19+
/** Allows code to check `instanceof ShadowRoot`. */
20+
declare interface ShadowRootConstructor {
21+
new(): ShadowRoot;
22+
}
23+
declare const ShadowRoot: ShadowRootConstructor;

src/lib/parts.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,6 @@ export class PropertyCommitter extends AttributeCommitter {
404404

405405
export class PropertyPart extends AttributePart {}
406406

407-
declare global {
408-
interface EventListenerOptions {
409-
capture?: boolean;
410-
once?: boolean;
411-
passive?: boolean;
412-
}
413-
}
414-
415407
// Detect event listener options support. If the `capture` property is read
416408
// from the options object, then options are supported. If not, then the thrid
417409
// argument to add/removeEventListener is interpreted as the boolean capture
@@ -435,7 +427,7 @@ export class EventPart implements Part {
435427
eventName: string;
436428
eventContext?: EventTarget;
437429
value: any = undefined;
438-
_options?: {capture?: boolean, passive?: boolean, once?: boolean};
430+
_options?: AddEventListenerOptions;
439431
_pendingValue: any = undefined;
440432
_boundHandleEvent: (event: Event) => void;
441433

src/lib/shady-render.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ import {Template} from './template.js';
2222

2323
export {html, svg, TemplateResult} from '../lit-html.js';
2424

25-
declare global {
26-
interface Window {
27-
ShadyCSS: any;
28-
}
29-
class ShadowRoot {}
30-
}
3125

3226
// Get a key to lookup in `templateCaches`.
3327
const getTemplateCacheKey = (type: string, scopeName: string) =>
@@ -61,7 +55,7 @@ const shadyTemplateFactory = (scopeName: string) =>
6155
if (template === undefined) {
6256
const element = result.getTemplateElement();
6357
if (compatibleShadyCSSVersion) {
64-
window.ShadyCSS.prepareTemplateDom(element, scopeName);
58+
window.ShadyCSS!.prepareTemplateDom(element, scopeName);
6559
}
6660
template = new Template(result, element);
6761
templateCache.set(result.strings, template);
@@ -137,8 +131,8 @@ const prepareTemplateStyles =
137131
// Note, it's important that ShadyCSS gets the template that `lit-html`
138132
// will actually render so that it can update the style inside when
139133
// needed (e.g. @apply native Shadow DOM case).
140-
window.ShadyCSS.prepareTemplateStyles(template.element, scopeName);
141-
if (window.ShadyCSS.nativeShadow) {
134+
window.ShadyCSS!.prepareTemplateStyles(template.element, scopeName);
135+
if (window.ShadyCSS!.nativeShadow) {
142136
// When in native Shadow DOM, re-add styling to rendered content using
143137
// the style ShadyCSS produced.
144138
const style = template.element.content.querySelector('style')!;
@@ -184,7 +178,7 @@ export const render =
184178
}
185179
// Update styling if this is the initial render to this container.
186180
if (!hasRendered) {
187-
window.ShadyCSS.styleElement((container as ShadowRoot).host);
181+
window.ShadyCSS!.styleElement((container as ShadowRoot).host);
188182
}
189183
}
190184
};

src/test/lib/incompatible-shady-render_test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const assert = chai.assert;
1818

1919
declare global {
2020
interface Window {
21-
ShadyDOM: any; // tslint:disable-line
2221
WarnCount: number;
2322
}
2423
}

src/test/lib/shady-render_test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ import {renderShadowRoot} from '../test-utils/shadow-root.js';
1717

1818
const assert = chai.assert;
1919

20-
declare global {
21-
interface Window {
22-
ShadyDOM: any; // tslint:disable-line
23-
}
24-
}
25-
2620
suite('shady-render', () => {
2721
test('style elements apply in shadowRoots', () => {
2822
const container = document.createElement('scope-1');

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "es2017",
44
"module": "es2015",
55
"lib": ["es2017", "esnext.asynciterable", "dom"],
6+
"types": ["chai", "mocha"],
67
"declaration": true,
78
"declarationMap": true,
89
"sourceMap": true,
@@ -12,8 +13,7 @@
1213
"noUnusedLocals": true,
1314
"noUnusedParameters": true,
1415
"noImplicitReturns": true,
15-
"noFallthroughCasesInSwitch": true,
16-
"skipLibCheck": true
16+
"noFallthroughCasesInSwitch": true
1717
},
1818
"include": [
1919
"src/**/*.ts"

0 commit comments

Comments
 (0)