I'm porting some code to TypeScript, and a bit stumped by this error. The SomeObject type is supposed to allow an object with any named keys which equate to string values. When using in unpacked argument fields, I get two errors:
'SomeObject' is declared but its value is never read.
and
Cannot find name 'someArg'. Did you mean the instance member 'this.someArg'?
Here's the code:
type SomeObject = { [key: string]: string; }
class SomeClass {
someArg: SomeObject
constructor ({someArg: SomeObject} = {}) {
this.someArg = someArg
}
}
module.exports = SomeClass;
Here you can see where TypeScript has a problem in VS Code:
Am I missing something? I would expect to be able to create an instance of this class like so:
new SomeClass({someArg: {hello: 'world'}}) // Passes TypeScript
new SomeClass({someArg: {hello: 1}}) // Fails TypeScript as value is not a string

{someArg: SomeObject} = {}- this doesn't looks right to me. Is this destructuring or are you specifying type forsomeArg? My guess is that this ambiguity is causing the issue.