Skip to content

why does initialization narrow type? #8513

Description

nightly build

"compilerOptions": {
        "module": "amd",
        "moduleResolution": "classic",
        "noEmitOnError": true,
        "allowUnreachableCode": false,
        "allowUnusedLabels": false,
        "outDir": "./built",
        "noResolve": true,
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "target": "es5"
        // "strictNullChecks": true
    }
export type Optional<a> = Some<a> | None;

export interface None { readonly none: string; }
export interface Some<a> { readonly some: a; }

export const none : None = { none: '' };

export function isSome<a>(value: Optional<a>): value is Some<a> {
    return 'some' in value;
}

export function fn<r>(): void {
    let result: Optional<r> = none;
    isSome(result)
        ? result.some
        : undefined
}

image

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions