Skip to content

Trying to implement Logic using the the type-system #35320

Closed
@damodharanj

Description

@damodharanj
type Bool = 'true' | 'false'

type Or<A extends Bool, B extends Bool> = A extends 'true' ? 'true' : B;

type And<A extends Bool, B extends Bool> = A extends 'true' ? B extends 'true' ? 'true' : 'false' : 'false';

type Not<T extends Bool> = T extends 'true' ? 'false' : 'true';

type Test = Not<'true'>

type Test1 = Not<'false'>

type Test3 = Not<Or<'true', 'false'>>

type Test4 = And<Not<'true'>, Not<'false'>>

function test(a: Bool): Not <typeof a> {
    switch (a) {
        case 'false': return 'false';
        case 'true': return 'true';
    }
}

The test function is supposed to return 'true' for input 'false' and vice-versa. But I don't get a error for the above implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions