-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
AdditionalProperties in swagger definition creates broken TS interface #525
Comments
@ph3b Thank you for your report. |
Hi, I'm using this from a c# side. I'm going to hack my instance to the following My generated snippet is
the doc is
|
@horiuchi export interface MicrosoftAspNetCoreMvcProblemDetails {
[name: string]: {
[key: string]: any;
} | unknown;
... |
@npdev453 |
Hello, I'm stumbling against something similar and found this issue, I believe in my case what would work best in case of having a schema: type: object
additionalProperties: false would be to generate the following Typescript: Record<any, never>
// or alternatively:
{ [key: string]: never } In this case, since the pattern already appears within
|
Hey @horiuchi, I indeed got a bit mixed up and #555 doesn't quite fix this issue, which apparently has more to do with TS way of having generic + specific keys in an object. I do still believe that the PR still adresses a real issue of having incorrect TS generated for the schema: type: object
additionalProperties: false and that it should get fixed. Should I first open an issue for this? Would you like to see anything else to get it merged? |
Hi @tdeo, Since TypeScript interfaces are essentially open-ended, we cannot express that They do not have additional properties. In the case of function f(): never { throw new Error() }
interface A {
[name: string]: never;
}
const a: A = {
test: f(),
}; So, I think it is better to ignore |
@npdev453 When I tried this in the past, all the properties were export interface MicrosoftAspNetCoreMvcProblemDetails {
[name: string]: { [key: string]: any; } | unknown;
type: string;
title: string;
status?: null | number; // int32
detail: string;
instance: string;
}
const x: MicrosoftAspNetCoreMvcProblemDetails = {} as any;
let a = x['type'];
// ^? string
let b = x.status;
// ^? number | null | undefined
let c = x['foo'];
// ^? unknown |
Hi!
First of all, great library! Have been using it for a long time and saves so much time aligning contracts between frontend and backends. Great work!
Today I stumbled upon a weird bug while upgrading rom v2 -> v3.
In my swagger definition I have the following object:
This get's "translated" to the following TS interface:
Which TypeScript immediately complains about with the following message:
Property 'title' of type 'string' is not assignable to 'string' index type '{ [key: string]: any; }'.ts(2411)
Using:
dtsgenerator: 3.13.2
typescript: 4.4.4
The text was updated successfully, but these errors were encountered: