Comments (3)
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.
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.
We now have the machinery in place to drop goog.require
and just use ES6 imports. Closing this issue.
from clutz.
Related Issues (20)
- test class_extends_array.js FAILED after 20190115 HOT 2
- Fix externs: DOMRect
- [gents] arrow functions with a single argument are not emitted properly syntactically HOT 1
- clutz should emit 'unknown' when translating '*'
- enum aliases are incorrectly emitted in partial mode HOT 4
- inner classes not emitted when outer class is emitted with named export
- declare legacy namespace + export obj + enum create wrong output HOT 1
- Static members on function not emitted
- gents does not handle goog.requireType HOT 2
- gents should convert @this
- Event vs KeyboardEvent
- Closure's `goog.isDefAndNotNull` seem to affect type inference and make clutz emit extra 'any's HOT 3
- JsDoc on static enums is not preserved
- clutz should not emit 'abstract' modifier on interfaces
- sonatype.org is erring with 'too many requests' on CI HOT 8
- Build are failing HOT 7
- Filter by Custom Tags Question HOT 4
- Do you use Clutz? How? HOT 2
- error: cannot find symbol import com.google.javascript.rhino.jstype.FunctionType.Parameter; HOT 6
- Question: externsMap on goog standard library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clutz.