microsoft / microsoft/TypeScript

Any type is inferred when function input parameter is set to some value

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

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

Bug Domain: check: Type Inference Needs Human Review Needs More Info
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

TypeScript Version: 3.8.2

Search Terms: any type is inferred

Code

interface ContinuationQueryResult<T> {
    documents: T[];
    continuation?: string;
}

function abc(continuation?: string): Promise<ContinuationQueryResult<string>> {
    return <any>undefined;
}

async function test() {
    // When not explicitly set to undefined type is inferred correctly.
    let continuation: string | undefined = undefined;

    do {
        const summaries = await abc(continuation);

        continuation = summaries.continuation;
    } while (continuation)
}

Expected behavior:
Type of summaries variable should be ContinuationQueryResult<string>.

Actual behavior:
summaries variable is inferred as any.

Playground Link: https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgMIHtygK5zMTARW2gE8AlCAZ2wBswAeAFQD5kBvAWAChk-kAJugTYAthHBUAXMiYBtALoBuHv2QJM+ELnyYA-DKpgooAOYruAXx48Y2EAl0hkcAEYIAFBqza8BEAbIRiYgpgCUMgAKUOiiwFQQDBg+Ov7EZJQ09AzBZixsXLz8UBBg2FDODHAgpCz2AhAwoBACFtbcPHBUpA7Idg5OyJBGHmEcqvwA9JPIAOoAFhLIIOhgyBAAHgAOtMAIwGC0pEGlQ+jI9Y3NAkOkWyjxyKAw0CU3GlAljkcAdBN8tFO3i0qUwhmMZmQAB8LiAGk0QC1kABeWHw64Wf6Cc6FNRqbxGIJiURwEzUFEuADucAOLncXk0OD8mDCmKKePUjN8g1RNFEJLJVB+wKZTgsaksyEp82AgOQDJSzJAYR4liAA

Related Issues:

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 bản tái hiện TypeScript Playground được liên kết và hàm kiểm thử, so sánh việc suy luận khi continuation được khởi tạo bằng undefined thay vì một giá trị khác. Truy theo đường dẫn kiểm tra kiểu cho đối số tùy chọn và thêm một bài kiểm thử hồi quy; hoàn thành khi summaries được suy luận là ContinuationQueryResult thay vì any.

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
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/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.