←back to thread

517 points bkolobara | 10 comments | | HN request time: 0.207s | source | bottom
1. gedy ◴[] No.45042251[source]
> Assigning a value to 'window.location.href' doesn't immediately redirect you, like I thought it would.

That's not a "Typescript" or language issue, that's a DOM/browser API weirdness

replies(3): >>45042856 #>>45043364 #>>45045727 #
2. gavmor ◴[] No.45042856[source]
Jeeze, why should attribute assignment have side-effects, anyway? That'd be gross!
replies(1): >>45048440 #
3. love2read ◴[] No.45043364[source]
*though it could have been fixed by typescript had they cared.
replies(1): >>45043549 #
4. morcus ◴[] No.45043549[source]
How could Typescript have fixed this?
replies(1): >>45044233 #
5. love2read ◴[] No.45044233{3}[source]
they could have provided a seperate api over top of this and error’d on use? It’s a clearly error-prone api.
replies(2): >>45044494 #>>45049887 #
6. morcus ◴[] No.45044494{4}[source]
I genuinely don't understand - how could Typescript provide a separate API on top of this? I usually do not expect Typescript to start generating code and APIs for me.

Also, Typescript is adding types on top of the JavaScript language, not the DOM API.

7. ChadNauseam ◴[] No.45045727[source]
You could argue that the DOM API being weird is partially because typescript didn't exist when they came up with the API, so the API wasn't designed with typescript in mind. If the DOM API was written against Rust, the API could have been designed against Rust's type system to make this error more difficult.
8. scheme271 ◴[] No.45048440[source]
I think it's unavoidable for any sufficiently complicated object or variable. Think of c++'s unique_ptr that guarantees that only a single reference to memory exists so that that the memory can be free'd safely when it goes out of scope. Or thing of a complicated object that has references to allocated memory. You either allocate a bunch of memory and copy values over or have two objects refer to the same bit of allocated memory. Each solution potentially has major downsides. Your objects don't even have to be all that exotic, think of a vector holding 1024 fp64 values or a 8kb long string.
replies(1): >>45076416 #
9. extraisland ◴[] No.45049887{4}[source]
No they shouldn't have done. The Browser API Implementation doesn't exist in TypeScript. It exists in the browser. TypeScript shouldn't be fixing how the browser behaves.

Think about what is happening. When you build to the browser as a target, TSC basically transpiles the TypeScript code to JavaScript. The Browser APIs that Typescript provides are a bunch of type definitions. When it transpiles the code the only thing it can really do is check the types match up.

10. gavmor ◴[] No.45076416{3}[source]
Yikes, sharing the same bit of memory seems like a Demeter violation! Is it really all that common? Maybe I am too OOP-pilled to grok the sense of it.