Skip to content

Commit

Permalink
Fix ts2742 when resolving ts-common types
Browse files Browse the repository at this point in the history
This error has been plaguing me for ages. It appears to be caused by the
static inferred type of an io-ts codec depending on a type in a transitive
dependency. Explicitly importing those transitive types seems to help,
but that results in a bunch of unused imports, which is undesireable.

I've had some success fixing it by doing two things:
(1): Installing ts-common as a top level dep that's the same version as
all transitive dependencies on it.
(2): Reinstalling to allow npm to "dedupe" the package. This makes sure
imports to ts-common resolve at the top level rather than transitively.

However, with using lerna, deduping doesn't appear to work. But to make
things even more confusing, this error cropped up only in tron-payments,
but not in stellar-payments. Even though they're using identical package
versions and similar imports.

Then I stumbled across
microsoft/TypeScript#29808
which describes a very similar issue.

I ended up trying this commentors solution
microsoft/TypeScript#29808 (comment)
and that appeared to fix the issue.

This isn't a perfect solution, but it's the best I've found. Ideally
typescript should always generate portable declaration files, or at least
resolve to the top level module when installed.
  • Loading branch information
dylanseago committed Nov 6, 2019
1 parent ab28a47 commit 0e4155b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions packages/tron-payments/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"outDir": "dist/lib",
"paths": {
"#/*": ["./src/*"],
"@faast/ts-common": ["node_modules/@faast/ts-common"],
}
},
"exclude": ["node_modules", "dist"]
Expand Down

0 comments on commit 0e4155b

Please sign in to comment.