Closed lilnasy closed 10 months ago
Seems like that would be pretty confusing in TypeScript codebases.
your example, but in the latest proposal (not merged yet) we have:
if (array is [1, 2, ...let rest]) {}
if (path is /^file:\/\/(?<let filePath>.+)$/) {
} else if (path extends /^http:\/\/(?<let insecurePath>.+)$/) {}
// with https://github.com/tc39/proposal-do-expressions
match (fiveIntegers) {
[let a]: do { return ...; }
[let a, let b]: do { return ...; }
default: do { return ...; }
}
match (randomItem) {
{ numOrString: let num and Number }:
...;
{ numOrString: let str and String }:
...;
}
That is exactly how I imagined it. Love it!
and
as the keyword seems non-obvious but I'll look at the PR to see if it makes sense.
The proposal seems heavily influenced from compiled languages. I am curious if syntax similar to typescript's was considered.
If-block on an array
If-block on a string
Switch-block on an array
Switch-block on an object