dsherret / dsherret/ts-morph

How to get property type with implicit type.

Open
#1,400 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

Hello,

Im currently writing swagger json generator for adonisjs. For this purpose i need to get the type of the validator schema. The validator class looks like this:
```
import { schema, CustomMessages } from "@ioc:Adonis/Core/Validator";
import type { HttpContextContract } from "@ioc:Adonis/Core/HttpContext";

export default class PatchUserValidator {
constructor(protected ctx: HttpContextContract) {}

public schema = schema.create({
isActive: schema.boolean()
});

public messages: CustomMessages = {};
}
```
The dificultty comes with the implicit typing, because If i will call `class.getPropertyOrThrow("schema").getType().getText()` i will get `any` type. The only other options that occurs my mind is to parse the getText of the whole property by myself, but i hope there is a better solution.

Thank you for your time and have a nice day!

Contributor guide

Open the contributing guide

Research direction

Start with the getPropertyOrThrow("schema").getType().getText() call and the implicit schema.boolean() example in the issue. Investigate how ts-morph exposes inferred property types, then determine what API behavior or documentation would let callers retrieve the validator schema type without parsing getText() themselves.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.