From b385383f4d17b7743051d835bfe1dbb6c24f490e Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 22 Jul 2024 14:59:53 -0700 Subject: [PATCH 1/3] Fix lib const --- packages/compiler/src/core/library.ts | 6 +++--- packages/compiler/src/core/param-message.ts | 2 +- packages/http-server-javascript/src/common/reference.ts | 2 +- packages/http/src/payload.ts | 2 +- packages/http/test/multipart.test.ts | 2 +- packages/protobuf/src/transform/index.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/compiler/src/core/library.ts b/packages/compiler/src/core/library.ts index a8025ef17a..e9041ea85a 100644 --- a/packages/compiler/src/core/library.ts +++ b/packages/compiler/src/core/library.ts @@ -63,9 +63,9 @@ function createStateKeys( * const lib = createTypeSpecLibrary(libDef); */ export function createTypeSpecLibrary< - T extends { [code: string]: DiagnosticMessages }, - E extends Record, - State extends string = never, + const T extends { [code: string]: DiagnosticMessages }, + const E extends Record, + const State extends string = never, >(lib: Readonly>): TypeSpecLibrary { let emitterOptionValidator: JSONSchemaValidator; diff --git a/packages/compiler/src/core/param-message.ts b/packages/compiler/src/core/param-message.ts index df35803a69..8e8e5365ca 100644 --- a/packages/compiler/src/core/param-message.ts +++ b/packages/compiler/src/core/param-message.ts @@ -1,6 +1,6 @@ import type { CallableMessage } from "./types.js"; -export function paramMessage( +export function paramMessage( strings: readonly string[], ...keys: T ): CallableMessage { diff --git a/packages/http-server-javascript/src/common/reference.ts b/packages/http-server-javascript/src/common/reference.ts index 7feeb3d69c..e6af69fa18 100644 --- a/packages/http-server-javascript/src/common/reference.ts +++ b/packages/http-server-javascript/src/common/reference.ts @@ -253,7 +253,7 @@ export function emitTypeReference( default: reportDiagnostic(ctx.program, { code: "unrecognized-intrinsic", - format: { name: (type satisfies never as IntrinsicType).name }, + format: { intrinsic: (type satisfies never as IntrinsicType).name }, target: position, }); return "unknown"; diff --git a/packages/http/src/payload.ts b/packages/http/src/payload.ts index fda7a5536a..1beeeeef08 100644 --- a/packages/http/src/payload.ts +++ b/packages/http/src/payload.ts @@ -345,7 +345,7 @@ function resolveMultiPartBodyFromTuple( diagnostics.add( createDiagnostic({ code: "multipart-invalid-content-type", - format: { contentType, valid: multipartContentTypesValues.join(", ") }, + format: { contentType, supportedContentTypes: multipartContentTypesValues.join(", ") }, target: type, }) ); diff --git a/packages/http/test/multipart.test.ts b/packages/http/test/multipart.test.ts index 19989fd379..735a2e8e27 100644 --- a/packages/http/test/multipart.test.ts +++ b/packages/http/test/multipart.test.ts @@ -13,7 +13,7 @@ it("emit diagnostic when using invalid content type for multipart ", async () => expectDiagnostics(diagnostics, { code: "@typespec/http/multipart-invalid-content-type", message: - "Content type 'application/json' is not a multipart content type. Supported content types are: .", + "Content type 'application/json' is not a multipart content type. Supported content types are: multipart/form-data, multipart/mixed.", }); }); diff --git a/packages/protobuf/src/transform/index.ts b/packages/protobuf/src/transform/index.ts index 8a17febf32..1d506a9ebf 100644 --- a/packages/protobuf/src/transform/index.ts +++ b/packages/protobuf/src/transform/index.ts @@ -442,7 +442,7 @@ function tspToProto(program: Program, emitterOptions: ProtobufEmitterOptions): P reportDiagnostic(program, { code: "unsupported-intrinsic", - format: { type: t.name }, + format: { name: t.name }, target: t, }); From 8b1636cb20ac3120c2531d2b8802a91e26b5f385 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 22 Jul 2024 15:04:02 -0700 Subject: [PATCH 2/3] Create lib-const-2024-6-22-22-3-25.md --- .chronus/changes/lib-const-2024-6-22-22-3-25.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/lib-const-2024-6-22-22-3-25.md diff --git a/.chronus/changes/lib-const-2024-6-22-22-3-25.md b/.chronus/changes/lib-const-2024-6-22-22-3-25.md new file mode 100644 index 0000000000..c17edf07da --- /dev/null +++ b/.chronus/changes/lib-const-2024-6-22-22-3-25.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/compiler" +--- + +Add `const` template parameter to get the precise lib type From 5c2b7291a3c7bf2ba6b5c6e7f6577d1588782174 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 22 Jul 2024 15:04:35 -0700 Subject: [PATCH 3/3] Create lib-const-2024-6-22-22-3-26.md --- .chronus/changes/lib-const-2024-6-22-22-3-26.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .chronus/changes/lib-const-2024-6-22-22-3-26.md diff --git a/.chronus/changes/lib-const-2024-6-22-22-3-26.md b/.chronus/changes/lib-const-2024-6-22-22-3-26.md new file mode 100644 index 0000000000..e6c475b297 --- /dev/null +++ b/.chronus/changes/lib-const-2024-6-22-22-3-26.md @@ -0,0 +1,10 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http-server-javascript" + - "@typespec/http" + - "@typespec/protobuf" +--- + +Fix some diagnostic not showing the right message