Costa.
Costa.
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
🧐
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
However, how can i force func to be in SomeInterface?
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
function wrapper<T>(func: (args: any) => T, args: any) {
... log
const result = func(args)
... dispatch
}
function wrapper<T>(func: (args: any) => T, args: any) {
... log
const result = func(args)
... dispatch
}
smth like this right?
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
const result = wrapper(foo("123", 12))
const result = wrapper(foo("123", 12))
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
And dispatch some state actions
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
The wrapper has the function of logging into some file
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
Im not thinking about forcing bar into foo, its more like calling bar or foo get the return types calling a wrapper
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
@ mattpocock 🙏
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
I thought about getting the keys from SomeInterface but its does not work...
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
I think its a really tricky thing
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
Hey! thank you for helping me deranged . I think i'm not being precise... Lets say something like:
interface SomeInterface<T> {
foo(arg1: string, arg2: number): Promise<T>;
bar(arg1: string): void;
}

interface OtherInterface {
foo(arg1: string, arg2: number): Promise<string>;
bar(arg1: string): void;
}

const fn: OtherInterface["bar"] = (arg1: string) => {
throw new Error("Function not implemented.");
};

function wrapper(func: SomeInterface<string>["foo"]) {
//somthing
const result = func("something", 1);

//more something

return result;
}

const res = wrapper(fn);
interface SomeInterface<T> {
foo(arg1: string, arg2: number): Promise<T>;
bar(arg1: string): void;
}

interface OtherInterface {
foo(arg1: string, arg2: number): Promise<string>;
bar(arg1: string): void;
}

const fn: OtherInterface["bar"] = (arg1: string) => {
throw new Error("Function not implemented.");
};

function wrapper(func: SomeInterface<string>["foo"]) {
//somthing
const result = func("something", 1);

//more something

return result;
}

const res = wrapper(fn);
This will not work, cuz wrapper only accepts foo". it shoudl accept all functions from SomeInteface and it can not be hardcoded. The interface have more than 30 methods...
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
I was thinking about some generics approach
32 replies
TTCTheo's Typesafe Cult
Created by Costa. on 4/10/2023 in #questions
Use function as a parameter and preserve types
Kinda yes, but it could be any function from SomeInterface
32 replies
TTCTheo's Typesafe Cult
Created by Will on 2/23/2023 in #questions
Does anyone know of a way to programmatically lift classNames into typescript intellisense?
maybe i'm wrong but i dont think that's possible 🥸
82 replies