Repository navigation
allow constants for string literals types #6151
Description
Activity
- addedBy DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
on Dec 18, 2015 RyanCavanaugh commented
on Dec 18, 2015 MemberMore actionsWe can't do this since it would be a breaking change --
vowhas not previously introduced an entry in the type namespace, so doing so now would mean random types would start getting shadowed.typeof vowshould do what you want here (if we madeconsts be of their string literal type Daniel Rosenwasser (@DanielRosenwasser) please confirm?).zpdDG4gta8XKpMCd commented
on Dec 18, 2015 AuthorMore actionstypeof vowshould do what you want herein the expression context
typeof vowgets me"string"
in the type expression context it gets me"will never change", but it's a string literal type which I cannot assign to a variable... if we made consts be of their string literal type
if we assuming it's hasn't yet been done, then it answers it
DanielRosenwasser commented
on Dec 18, 2015 MemberMore actionsLike Ryan Cavanaugh (@RyanCavanaugh) said, in order to do
typeof vow, you'd need #5796. That said, I don't know if that PR will go in. The behavior isn't entirely ideal because it's not clear when you want the literal type and notstring.Here is the proposal: #6167 (comment)
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensusand removedBy DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
on Jan 15, 2016 What about allowing interpolated strings as string literal types. So:
const vow = "will never change"; let promise: `${vow}`;The issue in the OP should be fixed by #10676
Allowing string interpolation, or any form of string manipulation in type positions is not something we are looking to allow.
for this specific example, use
typeofoperator, e.g.let promise: typeof vow;and this should be"will never change".Reacted by Aluan Haddad, Erik Cupal, Daniel García, Steve Dignam, Adam Szmyd and Yurii KozhenovReacted by Erik Cupal, Daniel García and Adam SzmydReacted by Erik Cupal and Daniel García- addedFixedA PR has been merged for this issueA PR has been merged for this issueand removedIn DiscussionNot yet reached consensusNot yet reached consensus
on Dec 1, 2016 Aleksey-Bykov do you agree this proposal is covered by #10676 and
typeof?zpdDG4gta8XKpMCd commented
on Dec 1, 2016 AuthorMore actionsyes, it's solved, please clise
- locked and limited conversation to collaborators
on Jun 19, 2018