Skip to content

treat enums as never members of unknown types - #714

Open
bakkot wants to merge 1 commit into
mainfrom
enum-error
Open

bakkot wants to merge 1 commit into
mainfrom
enum-error

Conversation

@bakkot

@bakkot bakkot commented Jul 23, 2026

Copy link
Copy Markdown
Member

The type lattice is deliberately conservative; when it encounters a type name it doesn't recognize, like PrivateElement, it assumes that could hold anything and as such it is never an error to assign any value to something of that type.

This heuristic is generally necessary; e.g. a property key is a String or a Symbol, and "property key" is an unknown type, so it is good that ecmarkup does not regard it as an error to assign a String to an unknown type.

However, we don't and (I weakly believe) shouldn't define any types that hold enums. This means we can assume a type name we don't recognize cannot hold an enum, and so assigning an enum specifically to such a type is an error.

@nicolo-ribaudo
nicolo-ribaudo requested a review from a team October 23, 2026 10:27
Comment thread src/type-logic.ts
if (text === '*undefined*') {
return { kind: 'undefined' };
}
break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather put the unknown-non-enum case here and leave the final fall-through as unknown. Related, this switch is nearly exhaustive, it just doesn't contain record, which we have a type for. We should add it (either as part of this PR or not, don't care) to make it both more complete and easier to understand.

@michaelficarra

Copy link
Copy Markdown
Member

I'm a bit skeptical that we won't ever want to alias a union that includes an enum, but I'm willing to give it a shot.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants