ryancavanaugh / dts-dom Goto Github PK
View Code? Open in Web Editor NEWA DOM library for generating TypeScript declaration (.d.ts) files
License: Apache License 2.0
A DOM library for generating TypeScript declaration (.d.ts) files
License: Apache License 2.0
See title
Just came to say thank you. I'm writing some code that depends on the typescript types, based on the path inside the package (e.g. require('dts-dom/lib/index.ts')
). I'm not asking for any changes, however- if in the future you decide to only include your built /bin
directory (which many packages do), please consider it a breaking change for your version number. ๐๐ผ
Thanks again for this useful package!
SPACE
missing in function writeInterface()
before keyword extends
.
Line 1000 in 8c14dd8
a089078#diff-d5a4b3a0309f2337144861084c1014523cced561eb722cb9684c63f5e41e0567L972-R1004
Can you do a push for 0.0.15? My repo relies on the indexSignature changes recently added but they haven't made it to npm yet.
Thanks!
I'm trying to transform an API response into some type definitions. Unfortunately, some argument and property types are already strings in JSDoc notation, e.g. Array.<string|number>|Buffer
. I'm currently converting that to Array<string|number>|Buffer
so its valid TS, but I'm nervous about trying to parse it to determine the correct ts-dom
structure.
Is there a way to pass that to this library and have it emitted unmodified?
Is there a way to create a member with multiple types?
If I want to create a property I can only pass one type. But in typescript you can declare a class member like this:
declare class myClass {
prop: string | number;
}
Am I right that it's currently not possible?
Im using the latest version of this package (3.6.0) but the published version of this package is missing functions, e. g. interfaces does not support type parameters (left: repo version, right: published version in the registry):
This feature was added 6 years ago so it should be already published, right?
Looks like in the latest release (0.1.8) the generated files are not up to date with the latest source.
I recommend adding a prepublish script that builds the bin/
folder to ensure it is automatically updated when publishing.
look here https://github.com/RyanCavanaugh/dts-dom/blob/master/lib/index.ts#L663-L679
When the parameter is optional ( of the method in an interface), it won't print ?
.
Should those lines be replaced by writeMethodDeclaration(member)
?
Following up on this comment:
What happens if we add hundreds of tests like this, then decide that the default output formatting should place the brace on the next line, or that large type aliases of unions should be split into multiple lines? Now we have to hand-edit hundreds of string literals in a .ts file; that's a nightmare.
We could easily add snapshot tests with Jest to avoid migration issues like this. Would you be open to a PR that adds this?
The following
const intfA = dom.create.interface('A');
const intfB = dom.create.interface('B');
intfB.baseTypes.push(intfA);
const foo = dom.create.namespace('Foo');
const bar = dom.create.namespace('Bar');
foo.members.push(intfB);
foo.members.push(bar);
bar.members.push(intfA);
console.log(dom.emit(foo));
generates:
declare namespace Foo {
interface B extends A{
}
namespace Bar {
interface A {
}
}
}
Which causes error because A
isn't defined in namespace Foo
. It should be interface B extends Bar.A
.
Is this intended and the solution is to supply a dummy ObjectTypeReference
with full relative name, or it's a bug?
Is there a specific reason why you differ between functionDeclaration and methodDeclaration?
I ask because I was wondering why my class members won't be parsed :D
I'm not very familiar with TypeScript so forgive me if this is silly issue or in some way incompatible.
I would like to use this library to convert JSDoc comments to a typescript definition file (like the tsd-jsdoc projcect) but I run into problems when comments hit the writeDeclaration
function. In our library most everything is interpreted as a method by JSDocs since they exist inside our global namespace. There shouldn't theoretically be any reason they cannot be passed as an case in which calls writeFunction
.
I've attempted to get this working to put in a PR but am running into some type errors that I'm working through, you might know a better way to resolve this.
Added in TypeScript 3.0. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type
As far as I can see there is no possibility to create parameters with initial value like
function myFunc(param: boolean = false)
Do you have a suggestion how to extend the function create.parameter to pass in a default value? If a default value is passed, the parameter flags
can be implicit set to DeclarationFlags.Optional
.
I would create a PR, but I didn't find a good way to apply these changes without breaking the API.
Do you have any suggestions?
This is the closest authoratative reference I could find, although it appears to be quite old: https://github.com/microsoft/TypeScript/blob/master/doc/spec.md#102-namespace-body
The following is valid typescript, according to my [email protected]:
declare namespace N {
enum E {
A = "a",
B = "b",
}
}
and can be generated with
const n = dom.create.namespace('N')
const e = dom.create.enum('E')
e.members.push(dom.create.enumValue('A','a'))
e.members.push(dom.create.enumValue('B','b'))
n.members.push(e)
dom.emit(n)
However the type of n.members
, NamespaceMember[]
, does not include EnumDeclaration
.
In my code, I've worked around it with a // @ts-ignore
I'm happy to create a PR if you agree with this change.
Namespaces can contain enums:
declare namespace Fuu {
export enum Bar {
ONE: number;
TWO: number;
}
}
But the type NamespaceMember
is missing type EnumDeclaration
https://github.com/RyanCavanaugh/dts-dom/blob/master/package.json#L7
Looks like the file wasn't published to npm?
Great library, thanks for putting this together!
Is there a reason why the example comment is not JSDoc?
Your example:
declare namespace SomeNamespace {
// This is my nice interface
interface MyInterface {
getThing?(x: number): void;
}
}
I would expect the output to be:
declare namespace SomeNamespace {
/**
* This is my nice interface
*/
interface MyInterface {
getThing?(x: number): void;
}
}
I didn't find an example or definition on how to create parameters with a default value for dom.create.method
. Am I missing something or is this not supported yet?
I'm trying to generate the following:
declare interface PartitionService {
shell(req: ShellRequest): Promise<ShellResponse>;
}
Everything works fine except for the Promise<ShellResponse>
. I'm not sure how to generate that piece. Any help? Thanks!
how to generate codes blow ๏ผ
declare type typeBase = {
name:string;
age:number;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.