Coder Social home page Coder Social logo

vscode-ts-auto-return-type's People

Contributors

guillaumenury avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-ts-auto-return-type's Issues

Strict null check and discriminated unions

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.

When type is too long it gets cut

When I use it on a function with a really long explicit type I get this:

image

(This is not a visual thing this this actually the type stopping with "..."

Also possible for arrow functions?

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
});

extend to variables

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.

Thanks

I had to do a huge refactor, this saved me hours of work, thanks u ๐Ÿ’•

JSX.Element mistakenly inferred as Element

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.