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

Forbid deletion of required attributes #3146

Closed
w0rp opened this issue Aug 21, 2017 · 2 comments
Closed

Forbid deletion of required attributes #3146

w0rp opened this issue Aug 21, 2017 · 2 comments

Comments

@w0rp
Copy link

w0rp commented Aug 21, 2017

I have thought of something which would be a very good use of TSLint's ability to check for problems including type information, where it might not be acceptable to include a sanity check in TypeScript itself. I think it would be nice of TSLint had a rule for forbidding deletion of required attributes for objects.

Consider the following code.

const x = {foo: 3}
delete x.foo

The type of x is {foo: number}, but after the line which deletes the attribute foo, this is no longer true. TypeScript won't warn about about this at all, and allows you to delete any attribute at all.

I think TSLint should have a rule whereby deletion of optional attributes is allowed, but deletion of attributes which are non-optional is forbidden. This would help to eliminate more errors in your code.

Let me know what you think.

@ajafff
Copy link
Contributor

ajafff commented Aug 22, 2017

For the reference: here's the same feature request and discussion in the TypeScript repo microsoft/TypeScript#13783

@JoshuaKGoldberg
Copy link
Contributor

Note: per #4534, this issue will be closed in less than a month if no PR is sent to add the rule. If you really need the rule, custom rules are always an option and can be maintained outside this repo!

@w0rp w0rp closed this as completed Jul 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants