I accidentally typed :
instead of =
at line 2 of this piece of code.
Why is this valid Typescript? Shouldn't colon expect a known Type declaration on a property definition?
I am certain that there is somewhere in the TS spec that allows it, but what is the purpose?
export class CategoriesService {
private _url : "http://localhost:3000/someurl"; // ???????????
constructor(private http: Http) {}
getData(): Observable<Category[]> {
return this.http.get(this._url).map(res => res.json()); //fails here, as _url is undefined
}
}
These types are String Literal Types, which are useful in the context of union types, especially in discriminated unions that can be used to simulate pattern matching found in functional programming languages.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments