Add `const` template parameter to get the precise lib type (#3933)
Without that there is some loss of information
This commit is contained in:
Родитель
50a8ba2ad7
Коммит
6aad4a795f
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче