Manage a correct overload with typescript



  • Here is my code in a class :

      public dangerouslyAttachCustomTag(
        tagName: string,
        content: string,
        attributes?: AttributeObject
      ): VastElement<this>;
      public dangerouslyAttachCustomTag(
        tagName: string,
        attributes?: AttributeObject
      ): VastElement<this>;
      public dangerouslyAttachCustomTag(
        tagName: string,
        contentOrAttributes: AttributeObject | string,
        attributesIfContent?: AttributeObject
      ): VastElement<this> {
        const newElem = new VastElement(
          tagName,
          this,
          { attrs: "all" },
          contentOrAttributes as any, // how to remove this any ?
          attributesIfContent
        );
    
        this.childs.push(newElem);
        return newElem;
      }
    
    

    My concern here, is that i can call my class in this 3 ways :

    v.dangerouslyAddCustomTag("test1")
    v.dangerouslyAddCustomTag("test2", { id: "22" })
    v.dangerouslyAddCustomTag("test3", "content3", { id: "33" });
    
    

    But since my constuctor has this signature :

      constructor(
        name: string,
        parent: VastElementParent,
        baseInfos: VastElementInfos,
        content: string,
        attrs?: AttributeObject
      );
      constructor(
        name: string,
        parent: VastElementParent,
        baseInfos: VastElementInfos,
        attrs?: AttributeObject
      );
      constructor();
      constructor(
        name: string = "root",
        parent: VastElementParent = null,
        baseInfos: VastElementInfos = { attrs: [] },
        contentOrAttributes?: AttributeObject | string,
        attributesIfContent?: AttributeObject
      ) 
    
    

    I'm unable to remove the "any" in "dangerouslyAttachCustomTag".

    How the overload is supposed to allow that ?


Log in to reply
 

最新帖子

最新内容

  • S

    I developed a custom credential. It's all working fine except when I'm using remote desktop with /restrictedadmin option. The login to the machine succeeds without my code interaction.

    By looking at the logs, I see call to the Constructor of the class that implements ICredentialProvider without any call to filter or other methods.

    Am I missing something? Probably I should implement function that "deals" with this situation. I'm struggling to understand how the flow goes when using in restricted mode.

    I read few articles including this https://blog.ahasayen.com/restricted-admin-mode-for-rdp/ , but still I can't point on how to solve this.

    read more
  • S

    Try running these queries and for the last query it should show you the relationship name as "KNOWS".

    Query 1:

    Create (p:Person { name: "Abc" , place: "Usa"})

    Query 2:

    MATCH (p:Person) WHERE p.name = "Abc" CREATE (p1:Person { name: "xyz", place: "Canada" }), (p2:Person { name: "pqr", place: "England"}), (p)-[:KNOWS {since: 2001}]->(p1),(p1)-[:KNOWS {rating: 5}]->(p2)

    Query 3:

    MATCH (p:Person)-[:KNOWS]-(p1) WHERE p.name = "Abc" RETURN p, p1

    Abc - KNOWS -> xyz

    Update: I am not sure this is appropriate or not but I just tried giving long label for a relationship.

    enter image description here

    read more
  • S

    In Neo4J Browser, the Graph is shown with Edge labels truncated, with dots (...).

    I would like to display the Edge (Relationship) labels fully, without the triple dots (...).

    Is this possible?

    read more
  • S

    Compiler expects the .java file to be named by class name. For example, the file public class Employee{ .., ... } needs to be named as Employee.java

    read more
  • S

    This question already has answers here:

    Why are filenames in Java the same as the public class name? [closed] (7 answers)

    Closed 11 months ago.

    I am new to java. This is the code i wrote in a text editor and saved as .java file.

    public class Prime { public static void main(String[] args) { int num = 29; boolean flag = false; for(int i = 2; i <= num/2; ++i) { // condition for nonprime number if(num % i == 0) { flag = true; break; } } if (!flag) System.out.println(num + " is a prime number."); else System.out.println(num + " is not a prime number."); } }

    But, when i tried to compile this file through CMD. I got a message that the class is public and it has to be declared in Prime.java. I didn't understand this, so i removed public modifier. And then compiled the code and then it successfully created a CLASS file. What can i do to overcome the above problem?

    read more

推荐阅读

  • 1
  • 1
  • 2
  • 3
  • 2
  • 1
  • 3
  • 4