镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Readonly<T> miss all internal symbol keys #37182

Description

@LongTengDao

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:

Activity

  1. RyanCavanaugh commented on Mar 4, 2020

    @RyanCavanaugh
    Member

    Anders Hejlsberg (@ahejlsberg) wasn't this scenario the use case for #23592 ?

  2. ahejlsberg commented on Mar 4, 2020

    @ahejlsberg
    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.

  3. ahejlsberg commented on Mar 4, 2020

    @ahejlsberg
    Member

    See #24738.

  4. PSeitz commented on Mar 12, 2020

    @PSeitz

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Experimentation NeededSomeone needs to try this out to see what happens

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions