Function tsGetClassMemberAccessModifiers

  • Returns a map of the private and protected class properties and methods of the provided TypeScript code for a class.

    Parameters

    • code: string

      The TypeScript code string to extract the class member access modifiers from.

    Returns Record<string, "protected" | "private">

    A record where the keys are the names of the class members and the values are their corresponding access modifiers.

    Remarks

    This function does not handle public class members as they do not explicitly have an access modifier in TypeScript.

    Throws

    an error if the provided code string is not valid TypeScript code.

    Example

    const code = `
    class MyClass {
    private myPrivateMethod() {}
    protected myProtectedMethod() {}
    }`;
    tsGetClassMemberAccessModifiers(code);
    //=> { myPrivateMethod: 'private', myProtectedMethod: 'protected' }

Generated using TypeDoc