Skip to content

Commit dcc7894

Browse files
committed
chore: add ts to workflow
1 parent 9c841a7 commit dcc7894

5 files changed

Lines changed: 15 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
npm rm react react-dom
3636
npm i react@${{ matrix.react-version }} react-dom@${{ matrix.react-version }}
3737
- name: Validate
38-
run: npm run lint
38+
run: |
39+
npm run tsc
40+
npm run lint
3941
- name: Run tests
4042
run: npm run cy:ci

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dev": "next",
2323
"test": "cypress open -b chrome",
2424
"lint": "eslint --fix --ext .ts,.tsx src components pages",
25-
"tsc": "tsc",
25+
"tsc": "tsc -p tsconfig.build.json",
2626
"cy:run": "cypress run",
2727
"cy:ci": "start-server-and-test dev http://localhost:3000 cy:run"
2828
},

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@ const getLazyInitImages = (): string[] => {
3838
}
3939
return normInitImages;
4040
};
41-
const isInitImage = (src: string | undefined): boolean => getLazyInitImages().some((initImgSrc) => initImgSrc?.endsWith(src));
41+
const isInitImage = (src: string | undefined): boolean => getLazyInitImages().some(
42+
(initImgSrc) => src && initImgSrc?.endsWith(src),
43+
);
4244
const isInitSsr = (isSsrMode = false, src?: string): boolean => {
4345
if (isSsrMode && src && isBrowser && document.readyState !== 'complete' && isInitImage(src)) {
4446
return true;
4547
}
4648
return false;
4749
};
4850

49-
function normArg(obj: ImgArg | string): Omit<ImgArg, 'srcSet'> | { 'srcset': ImgArg['srcSet'] }
51+
function normArg(obj: ImgArg): Omit<ImgArg, 'srcSet'> | { 'srcset': ImgArg['srcSet'] }
52+
function normArg(obj: SourceArg): Omit<SourceArg, 'srcSet'> | { 'srcset': SourceArg['srcSet'] }[]
5053
function normArg(obj: SourceArg): Omit<SourceArg, 'srcSet'> | { 'srcset': SourceArg['srcSet'] }[]
5154
function normArg(obj: any): any {
52-
const nObj = typeof obj === 'string' ? { src: obj } : obj;
53-
const normObj = { ...nObj, srcset: nObj.srcSet };
55+
const normObj = { ...obj, srcset: obj.srcSet };
5456
delete normObj.srcSet;
5557
Object.keys(normObj).forEach((key) => {
5658
if (normObj[key] === undefined) {
@@ -78,7 +80,7 @@ const useProgressiveImage = ({
7880

7981
// eslint-disable-next-line consistent-return
8082
const image = useDeepCompareMemo<HTMLImageElement | undefined>(() => {
81-
const src = typeof imgArg === 'string' ? imgArg : imgArg.src;
83+
const src = typeof imgArg === 'string' ? imgArg : imgArg?.src;
8284
if (src && isBrowser && !isInitSsr(ssr, src)) {
8385
const img = document.createElement('img');
8486

@@ -94,7 +96,7 @@ const useProgressiveImage = ({
9496

9597
img.onload = rerender;
9698
img.onerror = handleError;
97-
Object.assign(img, normArg(imgArg));
99+
Object.assign(img, normArg(typeof imgArg === 'string' ? { src: imgArg } : imgArg!));
98100
return img;
99101
}
100102
}, [imgArg, sourcesArg, rerender, handleError, ssr]);

tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
4343

4444
/* Module Resolution Options */
45-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
4646
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
4747
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4848
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
@@ -67,6 +67,7 @@
6767
"skipLibCheck": true, /* Skip type checking of declaration files. */
6868
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
6969
},
70+
"include": ["src"],
7071
"exclude": [
7172
"node_modules"
7273
]

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"allowJs": true,
1010
"skipLibCheck": true,
11-
"strict": false,
11+
"strict": true,
1212
"forceConsistentCasingInFileNames": true,
1313
"noEmit": true,
1414
"esModuleInterop": true,

0 commit comments

Comments
 (0)