Narrow doesn't work on class properties #212
Answered
by
millsp
DetachHead
asked this question in
Q&A
-
🐞 Bug ReportDescribe the bug
Reproduce the buginterface Foo {
bar: Narrow<{hi: 'there'}>
}
class Bar implements Foo {
bar = {hi: 'there'} //error: Type 'string' is not assignable to type 'NarrowRaw<"there">'.
} Expected behaviorthe value of ScreenshotsAdditional contextts-toolbelt 9.5.3 |
Beta Was this translation helpful? Give feedback.
Answered by
millsp
Mar 4, 2021
Replies: 1 comment 3 replies
-
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 |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
millsp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Narrow
only works on generic types, that is to say on parameter input:or write a helper
Hope this will help