Skip to content

Commit f6e193c

Browse files
fix: explicitly declare void as the return type for functions which return nothing - to allow our package to work with typescript's strict:true option (#253)
This PR adds explicit `void` return types for functions that left them off. Leaving them off causes problems when consuming `@fastly/js-compute` from a TypeScript project that has `strict: true` specified in `tsconfig.json`, with errors such as the following: ``` TS7010: 'log', which lacks return-type annotation, implicitly has an 'any' return type. ``` Co-authored-by: Jake Champion <[email protected]>
1 parent 73a6cd2 commit f6e193c

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

sdk/js-compute/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,11 @@ declare class URLSearchParams {
474474
* **Note**: Messages are prefixed with the respective logel level, starting with an upper-case letter, e.g. `"Log: "`.
475475
*/
476476
declare interface Console {
477-
log(message: any);
478-
debug(message: any);
479-
info(message: any);
480-
warn(message: any);
481-
error(message: any);
477+
log(message: any): void;
478+
debug(message: any): void;
479+
info(message: any): void;
480+
warn(message: any): void;
481+
error(message: any): void;
482482
}
483483

484484
/**
@@ -521,7 +521,7 @@ declare interface Logger {
521521
/**
522522
* Send the given message, converted to a string, to this Logger instance's endpoint
523523
*/
524-
log(message: any);
524+
log(message: any): void;
525525
}
526526

527527
/**
@@ -553,7 +553,7 @@ declare interface Fastly {
553553
*
554554
* @experimental
555555
*/
556-
enableDebugLogging(enabled: boolean);
556+
enableDebugLogging(enabled: boolean): void;
557557

558558
/**
559559
* Retrieve geolocation information about the given IP address.
@@ -740,7 +740,7 @@ interface Request extends Body {
740740

741741
// Fastly extensions
742742
backend: string;
743-
setCacheOverride(override: CacheOverride);
743+
setCacheOverride(override: CacheOverride): void;
744744
}
745745

746746
declare var Request: {

sdk/js-compute/index.test-d.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ import {expectError, expectType} from 'tsd';
108108
expectType<CacheOverride>(new CacheOverride("override", {}))
109109
const cacheOverride = new CacheOverride('none');
110110
expectType<CacheOverrideMode>(cacheOverride.mode)
111-
expectType<boolean>(cacheOverride.pci)
112-
expectType<number>(cacheOverride.ttl)
113-
expectType<number>(cacheOverride.swr)
114-
expectType<string>(cacheOverride.surrogateKey)
111+
expectType<boolean | undefined>(cacheOverride.pci)
112+
expectType<number | undefined>(cacheOverride.ttl)
113+
expectType<number | undefined>(cacheOverride.swr)
114+
expectType<string | undefined>(cacheOverride.surrogateKey)
115115
}
116116

117117
// CacheOverrideInit
118118
{
119119
const cacheOverrideInit = {} as CacheOverrideInit
120-
expectType<boolean>(cacheOverrideInit.pci)
121-
expectType<number>(cacheOverrideInit.ttl)
122-
expectType<number>(cacheOverrideInit.swr)
123-
expectType<string>(cacheOverrideInit.surrogateKey)
120+
expectType<boolean | undefined>(cacheOverrideInit.pci)
121+
expectType<number | undefined>(cacheOverrideInit.ttl)
122+
expectType<number | undefined>(cacheOverrideInit.swr)
123+
expectType<string | undefined>(cacheOverrideInit.surrogateKey)
124124
}
125125

126126
// ClientInfo
@@ -267,11 +267,11 @@ import {expectError, expectType} from 'tsd';
267267
// console
268268
{
269269
expectType<Console>(console)
270-
expectType<(message: any)=>any>(console.log);
271-
expectType<(message: any)=>any>(console.debug);
272-
expectType<(message: any)=>any>(console.info);
273-
expectType<(message: any)=>any>(console.warn);
274-
expectType<(message: any)=>any>(console.error);
270+
expectType<(message: any)=>void>(console.log);
271+
expectType<(message: any)=>void>(console.debug);
272+
expectType<(message: any)=>void>(console.info);
273+
expectType<(message: any)=>void>(console.warn);
274+
expectType<(message: any)=>void>(console.error);
275275
}
276276

277277
// TextDecoder
@@ -299,7 +299,7 @@ import {expectError, expectType} from 'tsd';
299299
// Logger
300300
{
301301
const logger = {} as Logger
302-
expectType<(message:any) => any>(logger.log)
302+
expectType<(message:any) => void>(logger.log)
303303
}
304304

305305
// Fastly
@@ -313,7 +313,7 @@ import {expectError, expectType} from 'tsd';
313313
fastly.defaultBackend = '.';
314314
expectType<Env>(fastly.env);
315315
expectType<(endpoint: string)=> Logger>(fastly.getLogger);
316-
expectType<(enabled: boolean) => any>(fastly.enableDebugLogging);
316+
expectType<(enabled: boolean) => void>(fastly.enableDebugLogging);
317317
expectType<(address: string)=>Geolocation>(fastly.getGeolocationForIpAddress);
318318
expectType<(path: string)=>Uint8Array>(fastly.includeBytes);
319319
}

sdk/js-compute/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"module": "es2020",
55
"lib": ["es2019"],
66
"outDir": "./build",
7-
"strict": false,
7+
"strict": true,
88
"moduleResolution": "node",
99
"skipLibCheck": false,
1010
"forceConsistentCasingInFileNames": true

0 commit comments

Comments
 (0)