Skip to content

Narrow doesn't work on class properties #212

Answered by millsp
DetachHead asked this question in Q&A
Discussion options

You must be logged in to vote

Narrow only works on generic types, that is to say on parameter input:

class C<B> {
    b: F.Narrow<B>;

    constructor(b: F.Narrow<B>) {
        this.b = b
    }
}

const c = new C({a: 1})

or write a helper

const narrow = <T>(thing: Narrow<T>) => thing

interface Foo {
    bar: {hi: 'there'}
}

class Bar implements Foo {
    bar = narrow({hi: 'there'})
}

Hope this will help

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@DetachHead
Comment options

@millsp
Comment options

@millsp
Comment options

Answer selected by millsp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #211 on March 04, 2021 12:22.