Summary
The TypeSpec TypeScript generator for Azure Modular SDK incorrectly generates code that imports version from Node.js os module instead of using the client's API version string, causing TypeScript compilation errors.
Spector case link: https://github.com/Azure/typespec-azure/tree/main/packages/azure-http-specs/specs/azure/client-generator-core/api-version
Bug Details
- Component: TypeSpec TypeScript Generator (Modular SDK)
- Error Type: Incorrect import generation
- Affected Files:
*Context.ts files in generated Modular SDK clients
- TypeScript Error:
Type '() => string' is not comparable to type 'string'
Generated Code Issue
The generator produces incorrect code like this:
// ❌ INCORRECT - Generated by TypeSpec generator
import { version } from "os"; // This imports Node.js os.version() function
import { logger } from "../logger.js";
import { Client, ClientOptions, getClient } from "@azure-rest/core-client";
export function createHeader(options: HeaderClientOptionalParams = {}): HeaderContext {
// ... other code ...
clientContext.pipeline.addPolicy({
name: "ClientApiVersionPolicy",
sendRequest: (req, next) => {
// ...
req.url = `${req.url}api-version=${version}`; // ❌ version is a function, not string
// ...
},
});
return { ...clientContext, version } as HeaderContext; // ❌ Type error here
}
Summary
The TypeSpec TypeScript generator for Azure Modular SDK incorrectly generates code that imports
versionfrom Node.jsosmodule instead of using the client's API version string, causing TypeScript compilation errors.Spector case link: https://github.com/Azure/typespec-azure/tree/main/packages/azure-http-specs/specs/azure/client-generator-core/api-version
Bug Details
*Context.tsfiles in generated Modular SDK clientsType '() => string' is not comparable to type 'string'Generated Code Issue
The generator produces incorrect code like this: