Skip to content

Commit 087a02a

Browse files
Cast to 'unknown' instead of '{}' in double assertions (#7116)
Avoid casting through '{}' with 'foo as {} as Bar' and instead use 'unknown', i.e. 'foo as unknown as Bar'. This is the preferred method according to Google's style guide. Internal link: go/tsstyle#double-assertions.
1 parent aa14065 commit 087a02a

File tree

652 files changed

+788
-733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

652 files changed

+788
-733
lines changed

tfjs-backend-cpu/src/backend_cpu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class MathBackendCPU extends KernelBackend {
8282
if (dtype === 'string' && values != null && values.length > 0 &&
8383
util.isString(values[0])) {
8484
const encodedValues =
85-
(values as {} as string[]).map(d => util.encodeString(d));
85+
(values as unknown as string[]).map(d => util.encodeString(d));
8686

8787
outId = this.write(encodedValues, shape, dtype);
8888
} else {

tfjs-backend-cpu/src/kernels/Abs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export const abs = (args: {inputs: AbsInputs, backend: MathBackendCPU}) => {
4444
export const absConfig: KernelConfig = {
4545
kernelName: Abs,
4646
backendName: 'cpu',
47-
kernelFunc: abs as {} as KernelFunc,
47+
kernelFunc: abs as unknown as KernelFunc,
4848
};

tfjs-backend-cpu/src/kernels/AddN.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export function addN(args: {inputs: AddNInputs, backend: MathBackendCPU}):
4444
export const addNConfig: KernelConfig = {
4545
kernelName: AddN,
4646
backendName: 'cpu',
47-
kernelFunc: addN as {} as KernelFunc
47+
kernelFunc: addN as unknown as KernelFunc
4848
};

tfjs-backend-cpu/src/kernels/All.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ export function all(
7979
export const allConfig: KernelConfig = {
8080
kernelName: All,
8181
backendName: 'cpu',
82-
kernelFunc: all as {} as KernelFunc
82+
kernelFunc: all as unknown as KernelFunc
8383
};

tfjs-backend-cpu/src/kernels/Any.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ export function any(
7979
export const anyConfig: KernelConfig = {
8080
kernelName: Any,
8181
backendName: 'cpu',
82-
kernelFunc: any as {} as KernelFunc
82+
kernelFunc: any as unknown as KernelFunc
8383
};

tfjs-backend-cpu/src/kernels/ArgMax.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ export function argMax(
7373
export const argMaxConfig: KernelConfig = {
7474
kernelName: ArgMax,
7575
backendName: 'cpu',
76-
kernelFunc: argMax as {} as KernelFunc
76+
kernelFunc: argMax as unknown as KernelFunc
7777
};

tfjs-backend-cpu/src/kernels/ArgMin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ export function argMin(
7373
export const argMinConfig: KernelConfig = {
7474
kernelName: ArgMin,
7575
backendName: 'cpu',
76-
kernelFunc: argMin as {} as KernelFunc
76+
kernelFunc: argMin as unknown as KernelFunc
7777
};

tfjs-backend-cpu/src/kernels/AvgPool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ export function avgPool(
5757
export const avgPoolConfig: KernelConfig = {
5858
kernelName: AvgPool,
5959
backendName: 'cpu',
60-
kernelFunc: avgPool as {} as KernelFunc
60+
kernelFunc: avgPool as unknown as KernelFunc
6161
};

tfjs-backend-cpu/src/kernels/AvgPool3D.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ export function avgPool3D(args: {
4646
export const avgPool3DConfig: KernelConfig = {
4747
kernelName: AvgPool3D,
4848
backendName: 'cpu',
49-
kernelFunc: avgPool3D as {} as KernelFunc
49+
kernelFunc: avgPool3D as unknown as KernelFunc
5050
};

tfjs-backend-cpu/src/kernels/AvgPool3DGrad.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ export function avgPool3DGrad(args: {
108108
export const avgPool3DGradConfig: KernelConfig = {
109109
kernelName: AvgPool3DGrad,
110110
backendName: 'cpu',
111-
kernelFunc: avgPool3DGrad as {} as KernelFunc
111+
kernelFunc: avgPool3DGrad as unknown as KernelFunc
112112
};

0 commit comments

Comments
 (0)