Skip to content
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

New Object.values() type does not infer enums and results in unknown[]. #48

Open
Andyuu opened this issue Aug 1, 2024 · 1 comment
Open
Labels
working as intended Actually not a bug

Comments

@Andyuu
Copy link

Andyuu commented Aug 1, 2024

https://www.typescriptlang.org/play/?target=99&ts=5.5.4#code/JYOwLgpgTgZghgYwgAgPICMBWEFgMID2IAzmFAK64FTIDeAUMsgPQBUrjTryAShGOSglkcECKhQ4AT2QEYyAG5wANuQjFZ8sAAsUEEOQC20OOmUoADlAIXoYYOs0ixBLDjCdk3AAIW4kw1k0N1xkHTgwZAQiMDhQDR1La1soe0dRABNkYx0CDOIAOmQAFW1gDQRRZHQUKtdsUPDIqQJyKKgICIgs6mdkCAAPcvsQAHNkABECBCN9SIwGyIBZPIhlZAAKCdQlgEpZELACz1ZmTiVVdQAeYoA+DYIALmQAQQlpABlgAGsIG9vds9igBtAC6AG5OGwOEwvLx+IJhFV-JIZHJFCo1Bp0Yl+gZjJIzEkbHYHNj5HVDidkL5-HBAgRgoswtoIlEYnFhLirCTUmTnFkcto8oUSmUKlUan16u4WWyWm0EB0uj0aFVBsNQOMpjNjOAmbKVhk1pttnsDotjrDTudMdcANL9AaQED5ZAABWSdik9ogUgANMgAGr3TyyZ58aJQDJXe2BkP+ziAzakKBap0ut2OgD8weQz3xNRog0zGhzeee5BA3xABAA7iBdmDIUxodS+AIhBpke80fILlinLj9LNCeZkDyUmlydKqdaaX4AkEFrKmuzwJyEroJ16+elXdl+ML8kVSuUopLai5DnLmq12p1IKq+hrSOmdbN9SvQkaTVsdvsMq4FaXBnEwA7qA8zy0AAvsmVY1vWIDNvQULsO2CJdn0KLSE4vxSMwEEzsO+ImESO68tOTiUos1K0kujLfpEa7RBu8QssSU78pkh65CeYrnpUYhSjRq6sneirKk+shqmIr4jNq0yfvMN6-us-7mkBRwnGBeJkGS-xQa8vZfL8-zJsCqZaoGxSgihrbofOHaIt2Yg4X2yD4YRdrEduI4EqY46TqSjjoqJuB0Yu9LLjeLEcux3K7lRPFCiKp7ihewlXhaYnyveSqPt0MkvkMb5jJMSl6ipzJqaaAE5cBOmcHMaYOhm+hup6lE+n68ahrC4bwlGMZxsGtyJkwFlWWMgbTeMJYdWWyC5kG+bIIW0Dta6S0rWtCG1g2dkQmhMJcPCnZIm5vZ4X63mXL5eikWOnEhTO4UePO9HRYxsXieusQJduwV7q5gpHmlAkSlls7MmuCoPiqxXqqVCkVbqcwGj+qzqWagGHCBXi6S1ZJGbBU36TNyD7UhR2QidGEXa5DWRKxAMgOmKjrEhFFTjIxrEEqwAWGA1BvdetGfVFDKY8xf2s5uHE869Aq8ceopnlD1TZVpt7IPDBWI70yOauVH5VTLyC1RpeOWk1TCjPwqANl1vMTOogvC6LNxbW6sH9bCTwlBNyDJgwA3Au6yCgJ5frorZQJSLYGQu96bsC2mntQDcEegrcLbIDByAAGR0GGwIDM8KepD1UigpXSVSGnHsi1A+cwZCMGof5yAAKLFOokRh73Az0hY44ALzIAA5IMo-mFP9Cd-QrGkBi93IJPTEFERGx9wPuzL0Qq-E44m-4yfxC7-3pC7EAA

In the above playground, you can see that both Object.values() and Object.entries() both come up with values of unknown[]. This is really not ideal behaviour.

https://www.typescriptlang.org/play/?target=99&ts=5.5.4#code/JYOwLgpgTgZghgYwgAgPICMBWEFgMID2IAzmFAK64FTIDeAUMsgPQBUrjTryAShGOSglkcECKhQ4AT2QEYyAG5wANuQjFZ8sAAsUEEOQC20OOmUoADlAIXoYYOs0ixBLDjCdk3AAIW4kw1k0N1xkHTgwZAQiMDhQDR1La1soe0dRABNkYx0CDOIAOmQAFW1gDQRRZHQUKtdsUPDIqQJyKKgICIgs6mdkCAAPcvsQAHNkABECBCN9SIwGyIBZPIhlZAAKCdQlgEpZELACz1ZmTiVVdQAeYoA+DYIALmQAQQlpABlgAGsIG9vds9ig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Gzx4nuwl0QZcPY4Vepa3xB1wnpC7EAA

The previous behaviour inferred them in what I believe is the correct way.

@uhyo
Copy link
Owner

uhyo commented Aug 1, 2024

Thanks for the feedback! I know this is inconvenient, but I had to make this change for safety.

See below example to know what was bad with the previous behavior.

enum ETest {
  Example = 'example',
}

const values = Object.values(ETest)
const entries = Object.entries(ETest)

const evilObject = {
  Example: ETest.Example,
  bad: 12345
};

const evilETest: typeof ETest = evilObject;

const values2 = Object.values(evilETest);
const entries2 = Object.entries(evilETest);

See also: #46

@uhyo uhyo added the working as intended Actually not a bug label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
working as intended Actually not a bug
Projects
None yet
Development

No branches or pull requests

2 participants