Skip to content

Commit

Permalink
[typescript]: Add workaround to include better typescript support.
Browse files Browse the repository at this point in the history
  • Loading branch information
aFarkas committed May 17, 2021
1 parent 27c7ceb commit 1523a4f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
grunt.file.write('lazysizes-umd.js', umd.replace('{{ls}}', ls));
});

grunt.registerTask('importTs', 'import global typescript.', function() {
const fileName = './lazysizes.d.ts';
const importStr = `import './types/global';\n\n`;
const tsContent = grunt.file.read(fileName);

grunt.file.write(fileName, importStr + tsContent);
});


// Default task.
grunt.registerTask("default", [ "wrapcore", "test", "uglify", "bytesize", "maxFilesize" ]);
Expand Down
3 changes: 1 addition & 2 deletions lazysizes-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
}
}(window,
/**
* import("./types/global")
* @typedef { import("./types/lazysizes-config").LazySizesConfigPartial } LazySizesConfigPartial
* @typedef { import("./types/global").LazySizesConfigPartial } LazySizesConfigPartial
*/
function l(window, document, Date) { // Pass in the window Date function also for SSR because the Date class can be lost
'use strict';
Expand Down
5 changes: 2 additions & 3 deletions lazysizes.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './types/global';

export = lazySizes;
declare var lazySizes: {
init: () => void;
Expand Down Expand Up @@ -53,9 +55,6 @@ declare var lazySizes: {
declare namespace lazySizes {
export { LazySizesConfigPartial };
}
/**
* import("./types/global")
*/
type LazySizesConfigPartial = {
[x: string]: any;
lazyClass?: string;
Expand Down
3 changes: 1 addition & 2 deletions lazysizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
}(typeof window != 'undefined' ?
window : {},
/**
* import("./types/global")
* @typedef { import("./types/lazysizes-config").LazySizesConfigPartial } LazySizesConfigPartial
* @typedef { import("./types/global").LazySizesConfigPartial } LazySizesConfigPartial
*/
function l(window, document, Date) { // Pass in the window Date function also for SSR because the Date class can be lost
'use strict';
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"author": "Alexander Farkas <[email protected]>",
"scripts": {
"prepublishOnly": "grunt && tsc"
"build": "grunt && tsc && grunt importTs",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions src/lazysizes-core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

/**
* import("./types/global")
* @typedef { import("./types/lazysizes-config").LazySizesConfigPartial } LazySizesConfigPartial
* @typedef { import("./types/global").LazySizesConfigPartial } LazySizesConfigPartial
*/
function l(window, document, Date) { // Pass in the window Date function also for SSR because the Date class can be lost
'use strict';
Expand Down
5 changes: 3 additions & 2 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import type * as lazySizes from '../lazysizes';
import { LazySizesConfigPartial } from './lazysizes-config';
import { LazySizesConfigPartial, LazySizesConfig } from './lazysizes-config';

export { LazySizesConfigPartial, LazySizesConfig };

export interface LazyUnveilReadEvent extends CustomEvent {
target: Element;
Expand Down

0 comments on commit 1523a4f

Please sign in to comment.