Skip to content

Commit

Permalink
Add const template parameter to get the precise lib type (#3933)
Browse files Browse the repository at this point in the history
Without that there is some loss of information
  • Loading branch information
timotheeguerin committed Jul 22, 2024
1 parent 50a8ba2 commit 6aad4a7
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .chronus/changes/lib-const-2024-6-22-22-3-25.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .chronus/changes/lib-const-2024-6-22-22-3-26.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions packages/compiler/src/core/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function createStateKeys<T extends string>(
* const lib = createTypeSpecLibrary(libDef);
*/
export function createTypeSpecLibrary<
T extends { [code: string]: DiagnosticMessages },
E extends Record<string, any>,
State extends string = never,
const T extends { [code: string]: DiagnosticMessages },
const E extends Record<string, any>,
const State extends string = never,
>(lib: Readonly<TypeSpecLibraryDef<T, E, State>>): TypeSpecLibrary<T, E, State> {
let emitterOptionValidator: JSONSchemaValidator;

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/core/param-message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CallableMessage } from "./types.js";

export function paramMessage<T extends string[]>(
export function paramMessage<const T extends string[]>(
strings: readonly string[],
...keys: T
): CallableMessage<T> {
Expand Down
2 changes: 1 addition & 1 deletion packages/http-server-javascript/src/common/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/http/src/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/http/test/multipart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down

0 comments on commit 6aad4a7

Please sign in to comment.