Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit deaa505

Browse files
committed
chore: add type checking script and refine TypeScript configuration
- Added a new script for type checking in package.json to ensure type safety during development. - Updated tsconfig.json to include specific TypeScript file patterns and exclude test files, improving the clarity and efficiency of the TypeScript compilation process. - Enhanced type safety in creds.ts by introducing a type guard for credential keys and ensuring proper checks before accessing credentials. - Refined error handling in login actions by explicitly typing the error as FetchError for better clarity. - Updated the loadCustomFieldsParser function to return undefined instead of null, aligning with TypeScript best practices for better type safety.
1 parent 76bf3aa commit deaa505

5 files changed

Lines changed: 12 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
"scripts": {
2727
"build": "unbuild",
28+
"typecheck": "tsc --noEmit",
2829
"release": "release-it",
2930
"dev": "pnpm run build && node dist/index.mjs",
3031
"lint": "eslint .",

src/commands/login/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const loginWithToken = async (token: string, region: RegionCode) => {
2828
throw new APIError('network_error', 'login_with_token', error);
2929
}
3030
}
31-
throw new APIError('generic', 'login_with_token', error, 'The provided credentials are invalid');
31+
throw new APIError('generic', 'login_with_token', error as FetchError, 'The provided credentials are invalid');
3232
}
3333
};
3434

src/commands/types/generate/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ const getComponentPropertiesTypeAnnotations = async (
252252
}, Promise.resolve({} as JSONSchema));
253253
};
254254

255-
const loadCustomFieldsParser = async (path: string) => {
255+
const loadCustomFieldsParser = async (path: string): Promise<((key: string, value: Record<string, unknown>) => Record<string, unknown>) | undefined> => {
256256
try {
257257
const customFieldsParser = await import(resolve(path));
258258
return customFieldsParser.default;
259259
}
260260
catch (error) {
261261
handleError(error as Error);
262-
return null;
262+
return undefined;
263263
}
264264
};
265265

@@ -280,7 +280,7 @@ export const generateTypes = async (
280280
try {
281281
const typeDefs = [...DEFAULT_TYPEDEFS_HEADER];
282282
const storyblokPropertyTypes = new Set<string>();
283-
let customFieldsParser: Record<string, unknown> | undefined;
283+
let customFieldsParser: ((key: string, value: Record<string, unknown>) => Record<string, unknown>) | undefined;
284284
let compilerOptions: Record<string, unknown> | undefined;
285285
// Custom fields parser
286286
if (options.customFieldsParser) {

src/creds.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { colorPalette, regionsDomain } from './constants';
77
import { getStoryblokGlobalPath, readFile, saveToFile } from './utils/filesystem';
88
import type { StoryblokCredentials } from './types';
99

10+
function isCredentialKey(k: string): k is keyof StoryblokCredentials {
11+
return k === 'login' || k === 'password' || k === 'region';
12+
}
13+
1014
export const getCredentials = async (filePath = join(getStoryblokGlobalPath(), 'credentials.json')): Promise<StoryblokCredentials | null> => {
1115
try {
1216
await access(filePath);
@@ -60,7 +64,7 @@ export const removeCredentials = async (region: RegionCode, filepath: string = g
6064
const credentials = await getCredentials(filePath);
6165
const machineName = regionsDomain[region] || 'api.storyblok.com';
6266

63-
if (credentials[machineName]) {
67+
if (isCredentialKey(machineName) && credentials) {
6468
delete credentials[machineName];
6569

6670
try {

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"isolatedModules": true,
2323
"skipLibCheck": true
2424
},
25-
"include": ["src"],
26-
"exclude": ["node_modules"]
25+
"include": ["src/**/*.ts", "src/**/*.tsx"],
26+
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx", "**/__tests__/**", "**/test/**", "**/tests/**"]
2727
}

0 commit comments

Comments
 (0)