Giter Site home page Giter Site logo

Comments (3)

PanayotCankov avatar PanayotCankov commented on May 18, 2024 1

If I could give some input, the best of my efforts is to use the following:

declare class Base {
    workBase();
    static Sub: typeof Base$Sub;
}
declare class Base$Sub {
    workBaseSub();
}


declare class Derived extends Base {
    workDerived();
    static Sub: typeof Base.Sub & typeof Derived$Sub; // halt type-check only if there are conflicts with base classes, or just return any & Derived$Sub
}
declare class Derived$Sub {
    workDerivedSub();
}

It however promises classes to be exposed as Base$Sub / Derived$Sub (this is valid JS identifier).

It can be then used as:

var b = new Base();
b.workBase();

var bs = new Base.Sub(); // Please note this approach still supports the dot subclass
bs.workBaseSub();

var d = new Derived();
d.workDerived();
d.workBase();

var ds = new Derived.Sub(); // Please note this approach still supports the dot subclass

// The Derived.Sub is magically resolved as Derived$Sub, although IMO this is a TS type system bug. we will probably have to use `any` if they fix this.
ds.workDerivedSub();

And then it would require us to use Derived$Sub when we refer to such conflicting nested classes.

from android-dts-generator.

Plamen5kov avatar Plamen5kov commented on May 18, 2024

There is an issue with the current representation of sub-classes in the typescript definition files.
Imagine this simplified example:

declare module A {
    export class Class1 {
    }
    export module Class1 {
        export class SubClass {
            public methodBase(): void;
        }
    }
}

declare module B {
    export class Class2 extends A.Class1 {
    }
    export module Class2 {
        export class SubClass {

        }
    }
}

Currently Class2 blows up with:

[ts] Class static side 'typeof Class2' incorrectly extends base class static side 'typeof Class1'.
  Types of property 'SubClass' are incompatible.
    Type 'typeof B.Class2.SubClass' is not assignable to type 'typeof A.Class1.SubClass'.
      Type 'B.Class2.SubClass' is not assignable to type 'A.Class1.SubClass'.
        Property 'methodBase' is missing in type 'SubClass'.

Which means, SubClass in Class2 can't have the same name as SubClass in Class1. At least not with the current syntax using module or namespace syntax, the way we do currently. This is a typescript compiler limitation. Unfortunately java compiler has no such issues.

This example is simplification of the android framework structure.

Class1 represents android.view.View

SubClass in Class1 represents: AccessibilityDelegate

Class2 represents android.support.v4.widget.NestedScrollView

SubClass in Class2 represents: AccessibilityDelegate

In the real scenario android.support.v4.widget.NestedScrollView inherits indirectly android.view.View, but the result is the same.

from android-dts-generator.

petekanev avatar petekanev commented on May 18, 2024

Closing this as I consider it resolved. Type inheritance is clear in the current state of the generated typings. The android.view.ViewGroup class for example will extend android.view.View and implement android.viewViewParent, as well as android.view.ViewManager, and declare their public members

from android-dts-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.