ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Get return type from ArrowFunction
I want to get the return type of an arrow function. Is it possible?
Here is my sample code
export const mySample = () => {
const result = {
name: 'Foo',
today: new Date()
}
return result;
}
export type MySampleType = ReturnType<typeof mySample>;
I'm using a simple configuration as following
import { createGenerator } from "ts-json-schema-generator";
const config = {
path: "./src/sample.ts",
tsconfig: "./tsconfig.json",
type: "*",
};
const schema = createGenerator(config)
.createSchema(config.type);
console.log(JSON.stringify(schema, null, 2));
It prints this output
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"NamedParameters<typeof mySample>": {
"type": "object",
"additionalProperties": false
},
"MySampleType": {}
}
}
I was expecting to get something like this.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"NamedParameters<typeof mySample>": {
"type": "object",
"additionalProperties": false
},
"MySampleType": {
"name": "string",
"today" "date"
}
}
}