타이프 라이터 인터페이스 정의에 대해

PoppinL :

I가 함수 B를 반환하는 기능 A가 함수 B의 PARAM 개체 C. C는 유형이있다 T. D라는 속성을 갖는다

내가 A 또는 다른 방법을 호출 할 때 나는 T를 설정할 수 있습니다 의미 B를 얻을 때 T가 결정된다.

어떻게 타이프에서 그것을 정의? 정말 고마워.


나는 작동하는이 시도했습니다. 하지만 내가 원하는 게 아니에요 :

interface C<T> {
    d: T;
    e: number;
}

interface B<T> {
    (param: C<T>): void;
}

interface A<T> {
    (): B<T>;
}

const a: A<number> = () => ({d, e}) => {
    console.log(d, e)
};

것들은 내가 좋아하는 어쩌면 무언가를 원하는 :

const a: A = () => ({d, e}) => {
    console.log(d, e)
};
const b1 = a<number>();
const b2 = a<string>();

나는 이것에 대해 아무 생각이 없습니다.

JeromeBu :

당신은 내가 유형보다는 인터페이스 청소기를 찾을 오른쪽 경로에 있습니다 :

interface C<T> {
    d: T;
    e: number;
}

type B<T> = (params: C<T>) => void

type A = <T>() => B<T>

// or inlined : type A = <T>() => (params: C<T>) => void

const a: A = () => ({d, e}) => {
    console.log(d, e)
};

const withNumber = a<number>();
const withString = a<string>();

추천

출처http://10.200.1.11:23101/article/api/json?id=377795&siteId=1