String Literal Type does not work #20271
Copy link
Copy link
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Activity
This is working as intended. The argument in the call to
fnis contextually typed byTypeAand therefore it is known that thetestproperty has a literal type. However, in theletassignment there is no contextual type, so the type of thetestproperty is widened tostringbecause the property is a mutable location.It works if you add a type annotation (thus providing a contextual type):
let obj: TypeA = { test: "test1" };
Duplicate of #17363 and others. For a discussion of the widening rules see #10676.
Reacted by Dave Druska- addedDuplicateAn existing issue was already createdAn existing issue was already created
on Nov 26, 2017 Thanks for your promoting reply.
- locked and limited conversation to collaborators
on Jun 14, 2018 - added a commit that references this issue
on Sep 10, 2019
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
TypeScript Version: 2.7.0-dev.201xxxxx
Code
Expected behavior:
Check pass
Actual behavior:
I get a TS2345