guillaumenury / vscode-ts-auto-return-type Goto Github PK
View Code? Open in Web Editor NEWVSCode extention that automatically print inferred return on your function !
VSCode extention that automatically print inferred return on your function !
First thanks for this extension, it is really quite handy. However, I recently hit a slightly annoying thing, is that it doesn't enable enforcing strict null check, which means that the following code doesn't produce the expected result with strict: true
enabled in my project:
function discriminatedUnionWithUndefined(input: string | undefined) {
return input;
}
I would have expected that to create the return type string | undefined
, but it actually only creates string
.
I could easily fix it by adding strictNullChecks: true
in the compiler options of createProgram
function in startNewExecution
of ts-auto-return-type
, but I'm not sure what would be the best way to properly fix this. I think the two options would be either to add an option to configure it, or try to read the current project configuration (through VSCode).
I don't mind making a PR if you don't have time, but before doing so I'd like to know your thoughts on that.
Hi!
Thanks for creating this extension, it's really useful!
Would it be also possible to use this for arrow functions? It is currently not doing anything for these functions:
const a = () => "hi"; // should be return type string
express.use((req, res) => { // should be void
// ...
// no return statement
});
Is it possible to extend your extension to create types also for variables, class members...?
const a = getString();
add type to variable declaration
const a:string = getString();
And similar:
class myAPI {
private internalDataSubject = new Subject<string>();
public apiDataLenght$ =
this.internalDataSubject.map(s=>s.length).toObservable();
...
add type to class member declaration
class myAPI {
private internalDataSubject = new Subject<string>();
public apiDataLenght$:Observable<number> =
this.internalDataSubject.map(s=>s.length).toObservable();
...
real example: In my api, I have public class members as observables, and to avoid future mistakes in internal logic, i must write theirs types.
I had to do a huge refactor, this saved me hours of work, thanks u ๐
Using:
export default function Home() {
return (
<div className="container"></div>
)
}
highlight the first line and run the plugin: it will infer Element but it's a JSX.Element and those are not the same types.
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.