Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-object-literal-type-assertion should have an option to allow const assertions #4628

Closed
InExtremaRes opened this issue Apr 2, 2019 · 2 comments · Fixed by #4681
Closed

Comments

@InExtremaRes
Copy link

Option to rule Suggestion

Since TypeScript 3.4 there are "const contexts for literal expressions" (microsoft/TypeScript#29510) that allow an as const statement in certain scenarios.

Right now the rule report an error:

// Type assertion on object literals is forbidden, use a type annotation instead.
let bar = { type: 'foo' } as const;

The new const assertions are really useful for complex type constructs, specially if they need to be used in discriminated unions.

So, add an option like "allow-const-assertions" to support this case would be very nice.

@adidahiya
Copy link
Contributor

Actually these assertions feel a little different to me than type assertions, so I'm tempted to just allow as const by default in the rule. Maybe if someone wants to ban them we can add that option later.

@InExtremaRes
Copy link
Author

@adidahiya Even better 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants