adl icon indicating copy to clipboard operation
adl copied to clipboard

TypeScript: support "useUnknownInCatchVariables" compiler option

Open bitc opened this issue 3 years ago • 5 comments

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

bitc avatar Oct 07 '21 14:10 bitc

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

timbod7 avatar Oct 09 '21 00:10 timbod7

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

bitc avatar Oct 09 '21 08:10 bitc

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.

timbod7 avatar Jan 18 '22 22:01 timbod7

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.

bitc avatar Jan 19 '22 14:01 bitc

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

paul-thompson-helix avatar Apr 28 '22 08:04 paul-thompson-helix