Skip to content

Location of declaration #88

Answered by Hookyns
carloszimm asked this question in Q&A
Jul 19, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Hi,
if getting the constructor by getCtor() is not enough, you can enable "server" mode if you want to know exact file locations. Then you can use type.constructorDescription property. See configuration.

Is this something you want?

import { getType, Type, AccessModifier, Accessor } from 'tst-reflect';

function logTypeDescription<T>() {
    console.log(getType<T>().constructorDescription);
}

export class SomeClass {
    property1: string = 'p1';
    property2: string = 'p2';
    property3: number = 3;

    get property4(): 'foo' | 'bar' {
        return 'foo';
    }

    constructor(a: string) {}

    method1(): void {}
}

logTypeDescription<SomeClass>();

// Get Ctor of the type, create…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@carloszimm
Comment options

@Hookyns
Comment options

@carloszimm
Comment options

Answer selected by carloszimm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants