I would much, much rather that type annotation syntax gets standardised first, because it is comparatively easy to build pattern matching when that's in place but going the opposite direction is difficult. What is a type if not a pattern?
Plus it's a stage1 proposal, meaning it's far from serious.
Could you link the type annotation proposal, I can't find it.
How do you match against a `Buffer` pattern/type?
case (value) {
when { constructor: Buffer } ->
console.log("It's a Buffer!")
}
that doesn't handle subtying though and doesn't work across realms.However I think my point stands that javascript has runtime conceptions of types that go beyond duck typing.
EDIT: here is the confirmation TS 3.7.0 got tagged: https://github.com/microsoft/TypeScript/issues/16#issuecomme...
EDIT 2: wow just noticed, that the issue ID is "16" and it has been open since Jul 15, 2014 (I guess: good things take time ... ;) )
I understand it's based on destructuring; the syntax still just doesn't work for me.
https://dev.to/kayis/pattern-match-your-javascript-with-z-nf...
See Scala[1] or Swifts[2]'s implementations.
[1] https://docs.scala-lang.org/tour/pattern-matching.html
[2] https://docs.swift.org/swift-book/ReferenceManual/Patterns.h...