Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 246716

Programming language created by Microsoft. Open source, and compiles to JavaScript.

2 votes
2 answers
342 views

Why don't variables in TypeScript implicitly infer literal typing?

Given a literal type, for instance 1 | 2, assigning a value to a variable that correctly corresponds to the literal type will fail. interface SomeInterface { foo: (1 | 2); } class SomeClass imple …
3 votes
Accepted

Why don't variables in TypeScript implicitly infer literal typing?

From @amon's comment: this behaviour indicates that the type checker does not inherit this info from the interface, but first type-checks the class (incl. type inference for foo) and then checks w …
Jacob Stamm's user avatar