Skip to content

Commit

Permalink
fix(CSS): fix for TypeScript 3.9+
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Jun 29, 2020
1 parent ed6ecaf commit a203936
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 4 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,13 @@
"publish": "npm run build && npm publish ./dist/common"
},
"description": "A set of common utils for consuming Web APIs with Angular",
"keywords": [
"angular",
"ng",
"window",
"api",
"web api",
"navigator",
"user agent"
],
"keywords": ["angular", "ng", "window", "api", "web api", "navigator", "user agent"],
"license": "MIT",
"author": {
"name": "Alex Inkin",
"email": "[email protected]"
},
"contributors": [
"Roman Sedov <[email protected]> (http://marsibarsi.me/)"
],
"contributors": ["Roman Sedov <[email protected]> (http://marsibarsi.me/)"],
"repository": "https://github.com/ng-web-apis/common",
"bugs": "https://github.com/ng-web-apis/common/issues",
"homepage": "https://github.com/ng-web-apis/common#README",
Expand Down Expand Up @@ -92,18 +82,15 @@
"tsickle": "0.34.0",
"tslint": "^5.18.0",
"tsutils": "^3.17.1",
"typescript": "3.1.6"
"typescript": "3.2.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && npm run typecheck"
}
},
"lint-staged": {
"*.{js,ts,html,md,less,json}": [
"prettier --write",
"git add"
],
"*.{js,ts,html,md,less,json}": ["prettier --write", "git add"],
"*.ts": "tslint"
},
"standard-version": {
Expand Down
15 changes: 9 additions & 6 deletions projects/common/src/tokens/css.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {inject, InjectionToken} from '@angular/core';
import {WINDOW} from './window';

declare global {
interface Window {
CSS: CSS;
}
/**
* Use Window['CSS'], this is a workaround to support Angular 6+
*/
interface Css {
escape(ident: string): string;
supports(property: string, value: string): boolean;
supports(conditionText: string): boolean;
}

export const CSS = new InjectionToken<CSS>('An abstraction over window.CSS object', {
export const CSS = new InjectionToken<Css>('An abstraction over window.CSS object', {
factory: () =>
inject(WINDOW).CSS || {
(inject(WINDOW) as any).CSS || {
escape: v => v,
supports: () => false,
},
Expand Down
1 change: 1 addition & 0 deletions projects/common/src/tokens/tests/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('CSS', () => {
it('injects window.CSS object', () => {
TestBed.configureTestingModule({});

// @ts-ignore
expect(TestBed.get(CSS)).toBe(window.CSS);
});

Expand Down

0 comments on commit a203936

Please sign in to comment.