Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Typescript compiler errors in console #1

Open
spacejack opened this issue Sep 20, 2017 · 11 comments
Open

Show Typescript compiler errors in console #1

spacejack opened this issue Sep 20, 2017 · 11 comments

Comments

@spacejack
Copy link

Would make the Typescript language support a lot nicer.

@porsager
Copy link
Owner

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

@pygy
Copy link
Contributor

pygy commented Sep 20, 2017

This for example should not pass type checking :-)

interface Foo {
  bar: string
}

const n: number = false

const foo:Foo = {bar: n}

console.log(foo)

@spacejack
Copy link
Author

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.)

@porsager
Copy link
Owner

porsager commented Sep 22, 2017

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..

@spacejack
Copy link
Author

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.

@porsager
Copy link
Owner

porsager commented Sep 23, 2017

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 ?

@spacejack
Copy link
Author

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.

@pygy
Copy link
Contributor

pygy commented Sep 24, 2017

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 :-)

@porsager
Copy link
Owner

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
Copy link
Owner

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 ?

@pygy
Copy link
Contributor

pygy commented Mar 29, 2018

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

ondreian referenced this issue in ondreian/flems Dec 22, 2022
fix: add allow-presentation to iframe sandbox;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants