Skip to content

withStatements

Reports using with statements

✅ This rule is included in the ts untyped presets.

with statements are deprecated, unreliable, and difficult to reason about. They are problematic because they add members of an object to the current scope, making it impossible to reliably know what a variable inside the block actually refers to. If an object doesn’t have an expected variable, you’ll end up modifying a global instead of the expected property.

with (
const container: any
container
.
any
property
) {
Error ts(1101) ― 'with' statements are not allowed in strict mode.
Error ts(2410) ― The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
any
value
= true;
}

This rule is not configurable.

If your codebase relies on non-standard behavior that involves with statements (which is highly discouraged), you might choose to disable this rule. For example, if you target a legacy runtime with non-standard JavaScript semantics, standard practices may not apply to you.

Made with ❤️‍🔥 around the world by the Flint team and contributors.