镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Omnibus fresh object subtype reduction / contextual type issue #19236

Description

// Problem 1: Error spans are useless in contextually-typed array/object literal cases
type Kind = 'foo' | 'ball';
// Error is on declared identifier instead of bad element
const ka: Kind[] = [
    'foo', 'ball', 'xxxx', 'foo', 'ball'
];
// Error is on declared identifier instead of bad key
const ko: { [s: string]: Kind } = {
    'x': 'foo',
    'y': 'xxxx',
    'z': 'foo'
};

// Problem 2: Subtype reduction screwage in the presence of contextual type
type OK = { ok?: boolean };
// No error??
const o1: OK = '??' ? { ok: 'wat' } : { };

// Problem 3: Aliased subtype reduction screwage
const obj = '??' ? { ok: 'wat' } : {};
// No error??
const o2: OK = obj;

Hypotheses:

  • Computing a union type in the presence of a contextual type is a waste of time
    • If we do this, we can produce good error spans?
  • Unioning { x: T } with a fresh { } should produce { x?: T }
  • Unioning a fresh object literal with { } should do something special
  • Unioning fresh { x: number, y: number } | { x: number } should produce { x: number, y?: number}

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions