flems icon indicating copy to clipboard operation
flems copied to clipboard

Show Typescript compiler errors in console

Open spacejack opened this issue 7 years ago • 11 comments

Would make the Typescript language support a lot nicer.

spacejack avatar Sep 20 '17 21:09 spacejack

Could you maybe post an example of some typescript code that should throw an error / warning?

porsager avatar Sep 20 '17 21:09 porsager

This for example should not pass type checking :-)

interface Foo {
  bar: string
}

const n: number = false

const foo:Foo = {bar: n}

console.log(foo)

pygy avatar Sep 20 '17 22:09 pygy

The simplest error might be to contradict an annotation, which should always be an error regardless of compiler settings:

const i: number = '1'

Here are some other examples that show errors with different compiler settings. (You can flip them on and off with the Options menu.)

spacejack avatar Sep 20 '17 23:09 spacejack

I've been looking closer at getting error output, but unfortunately it's not as straight forward as I had hoped. I currently use ts.transpileModule which bypasses any kind of diagnosis. To get the diagnosis a lot more complex API is required to be used (even though their docs state it is simple 😛).

This speaks for having an API in Flems to do type checking or linting etc, instead of trying to plug it in to the compilation phase.

The example from the typescript playground uses the monaco editor, and I tried to dig into the source of that, but it's heavily tied up inside and felt like finding a needle in a haystack.

I've found this documentation and this to be the best place to start for now.

It requires creating a program and then supplying that with a CompilerHost to simulate the file system.

Either digging in to that or participating in this issue to get the option in ts.transpileModule might be the way to go..

porsager avatar Sep 22 '17 18:09 porsager

Ah, it's too bad it's not a trivial undertaking. If I had the time I'd love to look into it but I really don't right now. There may be other TS users who would though, if you advertise it a bit. Just being able to run TS code is a pretty nice feature already.

spacejack avatar Sep 23 '17 17:09 spacejack

Hmm.. couldn't help myself.. I managed to get a bit further.. This definitely needs to be put in a worker, cause it seems quite heavy, but I think that might be possible to tweak by removing checks for errors not needed..

how does this look ?

porsager avatar Sep 23 '17 22:09 porsager

That's awesome!

The Cannot find name 'console' error should be fixed by adding compilerOptions.lib: ["dom"]. Doesn't look like that's an option for createProgram... hopefully those can be set somewhere.

spacejack avatar Sep 24 '17 18:09 spacejack

The Cannot redeclare block-scoped variable 'n'. (and 'foo') don't make sense to me. They are only defined once...

Edit:

That's awesome!

Yeah, doubling down on that :-)

pygy avatar Sep 24 '17 19:09 pygy

Thanks for the pointers :) I'll play around with it a bit more next week.. Also looked a bit into fetching type declarations with @spacejack on gitter, so I'll just leave this flems here because someone didn't implement saving flemses yet...

porsager avatar Sep 26 '17 08:09 porsager

I think this might be solved better by using the monaco editor and use the typescript checker it includes. I haven't found anything for CodeMirror unfortunately, there's only the js linter, but nothing typescript specific. What do you think @spacejack & @pygy ?

porsager avatar Mar 29 '18 10:03 porsager

I'm afraid I don't have any useful feedback...

pygy avatar Mar 29 '18 11:03 pygy