Comments (12)
Thanks for reporting this! I could have sworn I thought about function overloads. In this case, it's definitely better for us to stick exactly with the AST so I'll change getConstructor()
to getConstructors()
.
from ts-morph.
But isn't the issue that those parameters should be available in... I'm guessing getInstanceMembers, since they're declared with public modifiers?
from ts-morph.
Oh yeah, completely glossed over that because I started thinking about overloads. Anyway, the overload issue is fixed in 0.36.0. I think it's right that the parameters would be returned in getInstanceProperties() and getInstanceMembers().
from ts-morph.
Great - I really appreciate your responsiveness!
from ts-morph.
Ok, implemented in 0.37.0. I also fixed up some of the return types for these methods on ClassDeclaration... they were sometimes including types that would never be returned (too bad that typescript can't implicitly figure this out atm via the filter method).
Closing this. Let me know if this is still an issue. Also, I just happened to be around right now and I'm only doing quick fast releases because this is still very much a work in progress and experimental :)
from ts-morph.
I'll give it a shot this evening!
from ts-morph.
It does look like I'm getting these values now. One distinction - and maybe I'm wrong here - but properties are constructs like:
private _testField: string = null;
get fieldName() : string {
return this._testField;
}
set fieldName(name : string) {
this._testField = name;
}
This piece seemed to be working correctly before.
I don't think there's a way to define a property via the constructor parameters in which case those should only be appearing in the getAll/InstanceMembers return values whereas they are also being returned in the from the getInstanceProperties method call.
In any case, if I'm wrong, happy to be corrected but the "public" constructor params are now showing up as members.
from ts-morph.
The following error seems to have been introduced (I don't think it's my config):
node_modules/ts-simple-ast/dist/compiler/common/Node.d.ts(6,22): error TS2420: Class 'Node' incorrectly implements interface 'IDisposable'.
Property 'dispose' is missing in type 'Node'.
from ts-morph.
Sorry, Disposable error is gone in 0.37.1. I was trying to hide the dispose method because it's internal to the library, but forgot to hide it in the interface too. I still haven't implemented #33.
So parameters with a scope in a constructor are officially called "parameter properties" (see here). I think it's better to include them in getInstanceProperties()
because it will cause people who use this library to not forget about them (like how I forgot about them in this issue :)). It will give them a reminder that constructor parameters can possibly be properties too and that might be something they need to handle. If they don't need to worry about them, they can filter the parameters out of the returned results.
from ts-morph.
I just re-read over that typescript doc I linked to. I need getInstanceProperties()
to also return a result when people use the readonly
keyword hah (forgot about that because I never use only the readonly keyword with parameter properties... usually I only make them private readonly
). I'll fix that in 0.37.2.
Edit: Fixed. Actually fixed in 0.38.0 because I added isParameterProperty(): boolean
to ParameterDeclaration
.
from ts-morph.
Ok, I've just pulled this and will clean-up my code accordingly. Also, thanks for the clarification on parameter properties - very helpful!
from ts-morph.
@sfrooster fyi, in the upcoming 0.43.0, most methods in this library will only return the implementations of functions, methods, and constructors except when it's ambient. You can get the overloads by calling .getOverloads()
on the functions.
So for example:
const code = "function myFunction(str: string); function myFunction(num: number); function myFunction(strOrNum: string | number) {}";
const ast = new Ast();
const sourceFile = ast.addSourceFile("file.ts", code);
// this returns only 1 function declaration (the implementation) instead of 3
sourceFile.getFunctions();
const myFunction = sourceFile.getFunction("myFunction")!;
myFunction.getOverloads(); // returns the 2 overloads
That said...
const code = "declare function myFunction(str: string); declare function myFunction(num: number);`";
const ast = new Ast();
const sourceFile = ast.addSourceFile("file.ts", code);
// this returns the two function declarations because there is no implementation
sourceFile.getFunctions();
^ I'm mentioning this here because the same applies to getConstructors()
from ts-morph.
Related Issues (20)
- Organize Imports with specific ending for module node16
- transform doesn't handle recursively transformed nodes (fix suggested)
- .getChildSyntaxList() unexpectedly returns undefined for UnionTypeNode
- _ HOT 1
- `ImplementedKindToNodeMappings` does not include some types
- perf(Node.js): Major performance bottleneck in Node.js due to fs.statSync HOT 5
- enum addMember | insertMember
- `ts.sys` is `undefined` in Deno
- How do I get a single line comment HOT 1
- `DeclarationImport.remove()` removes following new line
- Property `getAssertClause` does not exist on type `ImportDeclaration`
- Q: How do I navigate source files from a dependency? HOT 1
- find if a declaration is used by next/dynamic imports HOT 1
- ClassDeclarationStructure has no support for static block structures
- Unable to rename bindingElement with usePrefixAndSuffixTextForRename:true
- docs: typo in the "source file dependency resolution" sub-section
- isEnum returns false when Enum property has a default value
- properties from type inference HOT 1
- [Question] Idiomatic way to insert before the return statement of a function?
- Add support for module specifier "aliases" (tsconfig.paths mappings) when moving files/folders.
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 ts-morph.