microsoft / microsoft/TypeScript

`Exclude<Exclude<T, null>, undefined>` is not assignable to `Exclude<T, null | undefined>` and vice versa

Đang mở
#38,142 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Needs Proposal Suggestion
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: Nightly

Search Terms:
typescript nullness inference

Expected behavior:
They should be assignable to each other.

Actual behavior:
They are not considered assignable to each other.

Type 'Exclude<Exclude<T, null>, undefined>' is not assignable to type 'Exclude<T, null | undefined>'.
  Type 'Exclude<T, null>' is not assignable to type 'Exclude<T, null | undefined>'.
    Type 'T' is not assignable to type 'Exclude<T, null | undefined>'.(2322)

and

Type 'Exclude<T, null | undefined>' is not assignable to type 'Exclude<Exclude<T, null>, undefined>'.
  Type 'T' is not assignable to type 'Exclude<Exclude<T, null>, undefined>'.(2322)

Related Issues:
N/A

Code

export function f<T>(v: Exclude<Exclude<T, null>, undefined>) {
    const w: Exclude<T, null | undefined> = v;
}

export function g<T>(v: Exclude<T, null | undefined>) {
    const w: Exclude<Exclude<T, null>, undefined> = v;
}

Output
export function f(v) {
    const w = v;
}
export function g(v) {
    const w = v;
}

Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với liên kết Playground được cung cấp và các hàm generic f và g dưới các tùy chọn trình biên dịch nghiêm ngặt đã liệt kê. Theo dõi cách trình biên dịch kiểm tra hai kiểu Exclude lồng nhau, sau đó xác minh rằng cả hai phép gán đều được chấp nhận mà không có các lỗi TS2322 được báo cáo, đồng thời giữ nguyên đầu ra được phát ra như đã hiển thị.

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
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.