Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const template parameter to get the precise lib type #3933

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading