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

Without that there is some loss of information
This commit is contained in:
Timothee Guerin 2024-07-22 15:25:40 -07:00 коммит произвёл GitHub
Родитель 50a8ba2ad7
Коммит 6aad4a795f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
8 изменённых файлов: 26 добавлений и 8 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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> {

Просмотреть файл

@ -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";

Просмотреть файл

@ -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,
})
);

Просмотреть файл

@ -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.",
});
});

Просмотреть файл

@ -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,
});