Skip to content

Readonly<T> miss all internal symbol keys #37182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LongTengDao opened this issue Mar 3, 2020 · 4 comments · Fixed by #42543
Closed

Readonly<T> miss all internal symbol keys #37182

LongTengDao opened this issue Mar 3, 2020 · 4 comments · Fixed by #42543
Labels
Experimentation Needed Someone needs to try this out to see what happens
Milestone

Comments

@LongTengDao
Copy link
Contributor

TypeScript Version: 3.8.3

Search Terms: readonly internal symbol

Code

const sym = Symbol();
const x :{
	readonly str :any
	readonly [sym] :any
	readonly [Symbol.iterator] :any
	readonly [Symbol.toStringTag] :any
} = {} as Readonly<{
	str :any
	[sym] :any
	[Symbol.iterator] :any
	[Symbol.toStringTag] :any
}>;

Expected behavior:

no error

Actual behavior:

TS2739 (missing properties Symbol.iterator and Symbol.toStringTag)

Playground Link:

Related Issues:

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Mar 4, 2020

@ahejlsberg wasn't this scenario the use case for #23592 ?

@ahejlsberg
Copy link
Member

wasn't this scenario the use case for #23592 ?

Yes, except we have always excluded "well known symbols" from keyof. The fix really is to get rid of the well known symbol concept and just treat them all as unique symbols.

@ahejlsberg
Copy link
Member

See #24738.

@RyanCavanaugh RyanCavanaugh added the Experimentation Needed Someone needs to try this out to see what happens label Mar 11, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 11, 2020
@PSeitz
Copy link

PSeitz commented Mar 12, 2020

This blocks converting Readonly Sets to Arrays

const mySet: Readonly<Set<string>> = new Set();
const myArr = [...mySet]; // Type 'Readonly<Set<string>>' must have a '[Symbol.iterator]()' method that returns an iterator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experimentation Needed Someone needs to try this out to see what happens
Projects
None yet
4 participants