microsoft / microsoft/TypeScript
Resolving hoisted `typeRoots` paths
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
TypeScript Version: 3.6.2
Search Terms:
- resolve typeRoots in parent package node_modules
- sharing tsconfig in yarn workspaces
- use hoisted tsconfig in child package
Code
I've set up a Lerna monorepo which uses Yarn Workspaces. Within this monorepo is a config package, which other packages depend on. This config package has @types/node and @types/jest as dependencies.
From sibling packages, the shared config is used like so:
{
"extends": "@project/config/ts.json",
"include": ["src", "tests"],
"compilerOptions": {
"outDir": "lib"
}
}
In the shared config, I point to the appropriate types root:
{
"compilerOptions": {
// ...
"typeRoots": ["node_modules/@types"]
}
}
However, within the shared config package, @types/* have been hoisted from the local node_modules to the monorepo's top-level node_modules. This behavior is usually fine given node's resolution... but it seems the config does not resolve to its parent's node_modules.
Expected behavior:
For the specified type root to resolve to the parent's node_modules
Actual behavior:
Tests fail with messages such as Cannot find name 'describe'. Do you need to install type definitions for a test runner? ...
One workaround:
{
"compilerOptions": {
// ...
"typeRoots": ["../../node_modules/@types"]
}
}
This workaround isn't very clean. Lerna & Yarn definitely pose some complexity for type root resolution. Hopefully resolving parents is considered a worthwhile modification.
Please let me know. Thank you :)
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện thiết lập Lerna và Yarn Workspaces với TypeScript 3.6.2 hoặc typescript@next, sử dụng typeRoots của cấu hình dùng chung và cấu hình extends của package anh em. Trước tiên, hãy theo dõi cách đường dẫn tương đối node_modules/@types được phân giải từ cấu hình dùng chung, sau đó xác minh rằng các định nghĩa kiểu của package cha được hoist được tìm thấy và các lỗi thiếu describe không còn xảy ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100