Giter Club home page Giter Club logo

Comments (3)

mhegazy avatar mhegazy commented on July 19, 2024

MyClass is a value, and not a type. it just happens to be a constructor function that when invoked with new operator returns objects of instance type of class MyClass.

so calling it with new will return the right thing, the problem is you can not name the type.

var myClassConstructorValue = goog.require('MyClass');
var myClassInstance = new myClassConstructorValue();

var anotherInstnace: typeof myClassInstance; // === type MyClass

I think what you want to say is something like microsoft/TypeScript#4233

from clutz.

rkirov avatar rkirov commented on July 19, 2024

Thanks for the explanation, that makes sense and has a good consistent mental model. The way I see it var-binding can only introduce new values.

The missing context here is that we are trying to craft a .d.ts that would allow a .ts file to typecheck, source code that is using goog.require.

This issue is a bit of wishful thinking, because only natively supported module imports do cary types through. For example for node modules the following works:

    import MyClass = require('./myclass'); 
    var c: MyClass = new MyClass();

and similarly for ES6 modules:

    import MyClass from './myclass'; 
    var c: MyClass = new MyClass();

I don't see how even more generalized typeof statements would let us shim goog.require to behave like compile supported modules. Anything that makes the user type more than :

    const MyClass  = goog.require('myclass'); 
    var c: MyClass = new MyClass();

is a non-solution, as we don't want to expose too much complexity to the authors of that code.

However, we will work with Closure team to support ES6 import statement as a full replacement for goog.require, and side step this issue completely.

from clutz.

mprobst avatar mprobst commented on July 19, 2024

We now have the machinery in place to drop goog.require and just use ES6 imports. Closing this issue.

from clutz.

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.