Problem description
Problem descriptionWhen compiling the @grpc/grpc-js-xds package with strict TypeScript checks, the build fails with a TS2345 error due to a type mismatch on PeerCertificate.subject.CN. The Node.js TLS definitions correctly type this as string | string[] | undefined, but the codebase passes it directly to nameMatcher.apply(), which strictly expects a string. This results in an exit code 1 and aborts automated Docker builds.
Reproduction steps
- Pull the Docker base image
docker.io/library/node:18-bookworm.
- Clone the
grpc/grpc-node repository and checkout commit 61208ea8557bdfa2d9ff5ce64e15943ae493c3e7.
- Navigate to the
packages/grpc-js-xds directory.
- Run the build command:
npm run generate-types && npm run generate-interop-types && npm run generate-test-types && npm run compile.
- Observe the TypeScript compiler fail on
src/rbac.ts at line 228.
Environment
- OS name, version and architecture: Host is Ubuntu 20.04.6 LTS x86_64; Container is Debian Bookworm (
node:18-bookworm Docker image).
- Node version: 18.x (via
node:18-bookworm).
- Node installation method: Docker Image.
- If applicable, compiler version:
tsc (TypeScript version bundled with @grpc/grpc-js-xds@1.13.0 dev dependencies).
- Package name and version:
@grpc/grpc-js-xds@1.13.0.
Additional context
This failure was observed during the automated Kokoro CI build for grpc_e2e_performance_gke. The specific compiler error output is:
src/rbac.ts:228:35 - error TS2345: Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
228 return this.nameMatcher.apply(info.peerCertificate.subject.CN);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in src/rbac.ts:228
npm error code 1
npm error path /pre/packages/grpc-js-xds
The issue stems from the assumption that the certificate's Common Name (CN) is always a strictly defined string, which conflicts with modern @types/node definitions reflecting that a CN can be an array or undefined. Adding a type guard or fallback string before nameMatcher.apply() should resolve this.
Problem description
Problem descriptionWhen compiling the
@grpc/grpc-js-xdspackage with strict TypeScript checks, the build fails with aTS2345error due to a type mismatch onPeerCertificate.subject.CN. The Node.js TLS definitions correctly type this asstring | string[] | undefined, but the codebase passes it directly tonameMatcher.apply(), which strictly expects astring. This results in anexit code 1and aborts automated Docker builds.Reproduction steps
docker.io/library/node:18-bookworm.grpc/grpc-noderepository and checkout commit61208ea8557bdfa2d9ff5ce64e15943ae493c3e7.packages/grpc-js-xdsdirectory.npm run generate-types && npm run generate-interop-types && npm run generate-test-types && npm run compile.src/rbac.tsat line 228.Environment
node:18-bookwormDocker image).node:18-bookworm).tsc(TypeScript version bundled with@grpc/grpc-js-xds@1.13.0 devdependencies).@grpc/grpc-js-xds@1.13.0.Additional context
This failure was observed during the automated Kokoro CI build for
grpc_e2e_performance_gke. The specific compiler error output is:The issue stems from the assumption that the certificate's Common Name (CN) is always a strictly defined string, which conflicts with modern
@types/nodedefinitions reflecting that a CN can be an array or undefined. Adding a type guard or fallback string beforenameMatcher.apply()should resolve this.