Skip to content

Commit 1523a4f

Browse files
committed
[typescript]: Add workaround to include better typescript support.
1 parent 27c7ceb commit 1523a4f

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

Gruntfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101
grunt.file.write('lazysizes-umd.js', umd.replace('{{ls}}', ls));
102102
});
103103

104+
grunt.registerTask('importTs', 'import global typescript.', function() {
105+
const fileName = './lazysizes.d.ts';
106+
const importStr = `import './types/global';\n\n`;
107+
const tsContent = grunt.file.read(fileName);
108+
109+
grunt.file.write(fileName, importStr + tsContent);
110+
});
111+
104112

105113
// Default task.
106114
grunt.registerTask("default", [ "wrapcore", "test", "uglify", "bytesize", "maxFilesize" ]);

lazysizes-umd.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
}
1010
}(window,
1111
/**
12-
* import("./types/global")
13-
* @typedef { import("./types/lazysizes-config").LazySizesConfigPartial } LazySizesConfigPartial
12+
* @typedef { import("./types/global").LazySizesConfigPartial } LazySizesConfigPartial
1413
*/
1514
function l(window, document, Date) { // Pass in the window Date function also for SSR because the Date class can be lost
1615
'use strict';

lazysizes.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './types/global';
2+
13
export = lazySizes;
24
declare var lazySizes: {
35
init: () => void;
@@ -53,9 +55,6 @@ declare var lazySizes: {
5355
declare namespace lazySizes {
5456
export { LazySizesConfigPartial };
5557
}
56-
/**
57-
* import("./types/global")
58-
*/
5958
type LazySizesConfigPartial = {
6059
[x: string]: any;
6160
lazyClass?: string;

lazysizes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
}(typeof window != 'undefined' ?
88
window : {},
99
/**
10-
* import("./types/global")
11-
* @typedef { import("./types/lazysizes-config").LazySizesConfigPartial } LazySizesConfigPartial
10+
* @typedef { import("./types/global").LazySizesConfigPartial } LazySizesConfigPartial
1211
*/
1312
function l(window, document, Date) { // Pass in the window Date function also for SSR because the Date class can be lost
1413
'use strict';

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"license": "MIT",
66
"author": "Alexander Farkas <alex@boffinhouse.com>",
77
"scripts": {
8-
"prepublishOnly": "grunt && tsc"
8+
"build": "grunt && tsc && grunt importTs",
9+
"prepublishOnly": "npm run build"
910
},
1011
"repository": {
1112
"type": "git",

src/lazysizes-core.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
/**
3-
* import("./types/global")
4-
* @typedef { import("./types/lazysizes-config").LazySizesConfigPartial } LazySizesConfigPartial
3+
* @typedef { import("./types/global").LazySizesConfigPartial } LazySizesConfigPartial
54
*/
65
function l(window, document, Date) { // Pass in the window Date function also for SSR because the Date class can be lost
76
'use strict';

types/global.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// import type * as lazySizes from '../lazysizes';
2-
import { LazySizesConfigPartial } from './lazysizes-config';
1+
import { LazySizesConfigPartial, LazySizesConfig } from './lazysizes-config';
2+
3+
export { LazySizesConfigPartial, LazySizesConfig };
34

45
export interface LazyUnveilReadEvent extends CustomEvent {
56
target: Element;

0 commit comments

Comments
 (0)