Comments (4)
Hi Andrii! Can you share a little more about your setup? Clutz is pretty much only meant to generate d.ts
files for TypeScript code that is eventually using goog.module
somewhere, and cannot be used to generate declarations for normal TypeScript code.
from clutz.
Hi Ryan, our library is written in ES5 code, it's based on Google Closure Library and minified via Google Closure Compiler. I just want to generate d.ts
file to make life easier for those users who include our library into their TypeScript projects.
Let's say I have those classes:
./MyNamespace.js:
/**
* @namespace
* @publish
* @name MyNamespace
*/
goog.provide('MyNamespace');
./MyUtilClass.js:
goog.require('MyNamespace');
goog.provide('MyNamespace.MyUtilClass');
/**
* @constructor
*/
MyNamespace.MyUtilClass = function() {};
/**
* @param {string} msg
*/
MyNamespace.MyUtilClass.prototype.log = function(msg) {
'use strict';
console.log(msg);
};
./MyClass.js
goog.require('MyNamespace');
goog.require('MyNamespace.MyUtilClass');
goog.provide('MyNamespace.MyClass');
/**
* @constructor
* @publish
*/
MyNamespace.MyClass = function() {
/**
* @private
* @type {MyNamespace.MyUtilClass}
*/
this.util_ = new MyNamespace.MyUtilClass();
};
/**
* @publish
* @export
* @param {number} x
* @param {number} y
* @return {number}
*/
MyNamespace.MyClass.prototype.add = function(x, y) {
'use strict';
this.util_.log('execute add');
return x + y;
};
/**
* @export
* @param {number} x
* @param {number} y
* @return {number}
*/
MyNamespace.MyClass.prototype.subtract = function(x, y) {
'use strict';
this.util_.log('execute subtract');
return x - y;
};
When I generate d.ts
file via Clutz, I get totally valid type definitions:
The problem is that I don't want to expose methods that are not marked by our custom @publish
tag. For example, I want to provide IntelliSense for MyClass#add
method, but I don't want to provide it for MyClass#subtract
.
Is it possible somehow to instruct Clutz to not include namespaces/classes/methods which are not marked by @publish
tag into d.ts
file? Or the only way to do that is to fork Clutz and change it?
Thanks for the help.
from clutz.
I think you'll need to do additional processing to allow using that library in TypeScript. Clutz generates d.ts
files for typings but cannot bridge the gap between the goog.module
module system and TypeScript's. If you're pre-compiling the library for them using Closure Compiler and shipping it on npm Clutz may not work here either, the type definitions it emits are specifically for loading the library via Closure's module system 😞
Going back to the original topic, the --skipEmitRegExp
is deprecated and shouldn't be used.
from clutz.
Thanks for the answer, I'm closing the issue.
from clutz.
Related Issues (20)
- 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
- 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
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.