Why is this not a syntax / compile time error?

Reinstate Monica

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
  }
}
Wickoo

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.

edited at
0

Comments

0 comments
Login to comment

Related

Why does MPI_REDUCE returns a syntax error at compile time?

There is no semicolon after while in do while loop, even then the code is not throwing syntax error or compile time error why

Why isn't the ArrayIndexOutOfBoundsException a compile time error?

Compile Error: Syntax error

rise compile-time error message with stream syntax

Compile/Syntax Error: Run-time error 3075: Syntax error in query expression

Compile Error Syntax Error Vba

Java Terminology: Why compile-time error and not compile-time exception?

Why is no compile-time error when calling an ambiguous ctor?

Why instance initialization block is not throwing compile time error for duplicate entry?

why java can run with a compile time error in eclipse

Compile time error: ambiguous on calling overloaded method. Why?

Casting child to parent - compile time error due to missing method - why?

Why exceptions are thrown by format() function instead of compile time error?

Why does this instanceof code work and does not cause a compile time error?

Why force constexpr have compile time error only?

Why does failed enable_if lead to compile time error?

Why upcasting works but downcasting gives compile time error?

Why an implicit conversion does not throw a compile time error?

Why the below code snippet is not giving compile time error?

Why isn't obvious NullReferenceException a compile-time error?

Why a missing package statement does not give a compile time error in java?

Why is && strict in compile time?

combobox error at compile time

Gflags Compile time error

Redefinition error at compile time

Getting Compile time error

Compile Time Error

ON CONFLICT not even compile with error syntax?