microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.29k stars 12.53k forks source link

checkJs should recognize properties assigned with lodash #32482

Open kevinszuchet opened 5 years ago

kevinszuchet commented 5 years ago

Search Terms

js, lodash, properties

Suggestion

Recognize properties of some object when using lodash assign method

Use Cases

Any initalization of an object using:

_.assign(obj, { ...someProps });

// Instead of
this.oneProp = oneProp;
this.anotherProp = anotherProp;

Examples

image

Checklist

My suggestion meets these guidelines:

nmain commented 5 years ago

Related https://github.com/microsoft/TypeScript/issues/31314

From what I know, this would be difficult to implement because typescript has no notion of a function call modifying the type of a passed argument by mutating the argument.

IllusionMH commented 5 years ago

For these simple cases you can use parameter properties

http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEDyB2BTAwuK0DeBYAUNf0wA9vBAC4BOArsGURQBQAOVARiAJbDQmIAKFIkwBc0MPACeAGmgt2XHmQAWiCgKGjxEgJSYAvrgLQAtomVEAJg13Y8RghTNUK8aMo4QAdL3VNoAQgBeQLclD29lVV8AbkMCAxw9IA

kevinszuchet commented 5 years ago

For these simple cases you can use parameter properties

http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEDyB2BTAwuK0DeBYAUNf0wA9vBAC4BOArsGURQBQAOVARiAJbDQmIAKFIkwBc0MPACeAGmgt2XHmQAWiCgKGjxEgJSYAvrgLQAtomVEAJg13Y8RghTNUK8aMo4QAdL3VNoAQgBeQLclD29lVV8AbkMCAxw9IA

Thanks for answer!

I know, but the fact is that I don't want to change all my constructors for avoid the checkJs errors on VS Code @IllusionMH