A
A
Alexey Nikolaev2019-10-24 13:14:30
typescript
Alexey Nikolaev, 2019-10-24 13:14:30

How can I force tsc to use the types of packets it checks instead of the types of its invocation site?

Good day.
Faced a confusing situation. There are several repositories: one main, and several shared libraries that are installed as node modules and linked locally using yarn link. Typechecking is done using the tsc utility.
To paint the picture, let's have a Vault repository that uses the Utils library. Utils has dayjs installed, which is a good lib for working with dates. She adds her type declarations, everything is ok. I use the built-in Dayjs type in some cases to operate on a given object.
The problem is this: when we run yarn tsc inside Utils to check the correct types of Utils itself, everything works, tsc sees the types from the dayjs library. And when I run tsc inside Vault, it fails with the message "cannot find type Dayjs", and refers to a line where I'm using one of the Utils package modules. In Vault itself, the dayjs library and the Dayjs type are not used anywhere!
In other words, tsc crawls into another repository and checks types there, but using declarations from the project in which it was called.
The solution in the forehead is to install the dayjs lib in the Vault. I'll resort as a last resort, because Vault uses a wrapper from Utils to work with the date.
I hope I have explained the problem clearly. Who faced? How to solve the problem?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2019-10-24
@Nipheris

In Vault itself, the dayjs library and the Dayjs type are not used anywhere!

What do you understand by use? Obviously, you need dayjs for execution, and it should be installed as a Utils runtime dependency. To get rid of such a dependency, you then need to put dayjs inside Utils in one way or another, for example, build Utils in the same rollup into a bundle. I really do not see the need for this - usually only end applications are bundled, and the fact that the library has transitive dependencies -
Another thing is if you see a problem in that information about the Dayjs TYPE is required. Then specify how you compile Utils into what and whether Dayjs is leaking through the Utils public interface.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question