Skip to content

TS doesn't see when we add symbol properties to functions. #29821

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

Open
anurbol opened this issue Feb 8, 2019 · 4 comments
Open

TS doesn't see when we add symbol properties to functions. #29821

anurbol opened this issue Feb 8, 2019 · 4 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@anurbol
Copy link

anurbol commented Feb 8, 2019

TypeScript Version: 3.4.0-dev.20190207

Search Terms:
function, property, symbol

Code

const mySymbol = Symbol()

interface Foo {
    [mySymbol]: true
    (): any
}

const foo: Foo = () => {} // error: 
// Property '[mySymbol]' is missing in type '() => void' 
// but required in type 'Foo'.
foo[mySymbol] = true

Expected behavior:
Just like with regular (non-symbol) props, show no error if the symbol property actually has been added .

Actual behavior:
There is an error.

Playground Link: link

@anurbol
Copy link
Author

anurbol commented Feb 8, 2019

What is the cleanest workaround BTW, anyone knows? I mean except adding as any after the function.

@anurbol anurbol closed this as completed Feb 8, 2019
@dragomirtitian
Copy link
Contributor

Object.assign can work

const foo: Foo = Object.assign(() => { }, {
  [mySymbol]: true as true // must cast, literal types will be widened here to boolean causing an error on assignment, but it will work with other things.
});

@anurbol anurbol reopened this Feb 8, 2019
@anurbol
Copy link
Author

anurbol commented Feb 8, 2019

@dragomirtitian Woah! Indeed! Cool! Thanks! 👍 👍 👍

@Andarist
Copy link
Contributor

This one was already fixed by #54726 , the given playground still doesn't work though and I prepared a fix for it here: #55357 . I think that this issue can already be closed since what I noticed is orthogonal, cc @jakebailey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants