You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on TS types, and got this error :
error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
Here is the story : I intend to promisify a type, that is to say take all the members of an interface and turn their type to a Promise, except for undefined.
So far so good, this works very well, and when I generate a proxy, all the expected behaviour works with this :
exporttypePromisify<T,S=any>={[PinkeyofT]: // for each property P in the type TT[P]extends(...args: infer A)=>undefined// if it is a function(args) -> undefined
? (this: S, ...args: A)=>void// turn it to function(args) -> void
: T[P]extends(...args: infer A)=> infer R// if it is a function(args) -> whatever
? (this: S, ...args: A)=>Promise<R>// turn it to function(args) -> Promise<whatever>
: Promise<T[P]>;// else turn the field to a Promise};
With interface Hello { sayHello(user: string): void } I get a promisified type that would contain the method signature sayHello(user: string): Promise<void>.
Usage : await proxy.sayHello('Bob')
Then I intend to let the user to 'depromisify' a member, in the case the return value would be Promise<void> :
The compiler doesn't complain on the type definition, but when I use it : proxy.sayHello[NOACK]('Bob');
I got :
error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '((this: any, msg: string) => Promise<void>) & { NOACK: (this: any, msg: string) => void; }'.
No index signature with a parameter of type 'string' was found on type '((this: any, msg: string) => Promise<void>) & { NOACK: (this: any, msg: string) => void; }'.
21 proxy.sayHello[NOACK]('Bob');
I tried the workaround explained here #24587
that is to say to cast the symbol to a string (the message I have) but it still doesn't work.
I'm using
"ts-node": "^8.3.0",
"typescript": "^3.6.3"
Any idea ?
Thanks !
The text was updated successfully, but these errors were encountered:
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.
Hi,
I'm working on TS types, and got this error :
error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
Here is the story : I intend to promisify a type, that is to say take all the members of an interface and turn their type to a Promise, except for undefined.
So far so good, this works very well, and when I generate a proxy, all the expected behaviour works with this :
With
interface Hello { sayHello(user: string): void }
I get a promisified type that would contain the method signaturesayHello(user: string): Promise<void>
.Usage :
await proxy.sayHello('Bob')
Then I intend to let the user to 'depromisify' a member, in the case the return value would be
Promise<void>
:The compiler doesn't complain on the type definition, but when I use it :
proxy.sayHello[NOACK]('Bob');
I got :
I tried the workaround explained here #24587
that is to say to cast the symbol to a string (the message I have) but it still doesn't work.
I'm using
"ts-node": "^8.3.0",
"typescript": "^3.6.3"
Any idea ?
Thanks !
The text was updated successfully, but these errors were encountered: