adl-lang / adl

ADL (Algebraic Data Language)
Other
210 stars 20 forks source link

TypeScript: support "useUnknownInCatchVariables" compiler option #145

Open bitc opened 3 years ago

bitc commented 3 years ago

Hi, it would be nice if the generated TypeScript code would be compatible with https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables

The fix is make sure that all "catch" blocks have an : unknown type annotation.

Thank you

timbod7 commented 3 years ago

Would this generated code work in older versions of typescript? Having had problems with this in the past, we test that the generate code works with typescript versions 2.9, 3.5 and 3.8 and deno 1.10. See:

https://github.com/timbod7/adl/tree/master/typescript/tests

bitc commented 3 years ago

I see, looks nice. I think it should be able to work also in older versions of TypeScript.

A quick-fix is to add @ts-ignore before every catch statement. But a cleaner solution should also be possible

timbod7 commented 2 years ago

FWIW, we normally turn off linting for all the generated code - there doesn't seem to be much value in lint checking code that wasn't written by humans.

bitc commented 2 years ago

That makes sense. I guess it comes down to how you organize your project.

Here is how I do things: I copy all of the adl generated TypeScript files directly into my project, and compile them all together along with my application code, using a single "tsconfig.json" file. This seems like the simplest way to do things, but then there is a problem if the settings I want in my "tsconfig.json" file are not compatible with the generated code.

An alternate approach would be to use a separate "tsconfig.json" file for the adl generated TypeScript code, but this makes the project setup more complex.

paul-thompson-helix commented 2 years ago

Addressed by https://github.com/timbod7/adl/pull/155