Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 1.13 KB

함수_리턴_타입,_파라미터,_Awaited의_활용.md

File metadata and controls

47 lines (38 loc) · 1.13 KB

문제

image

풀이

// GetLocationWeatherReturn, GetDetailedWeatherParameters 에 커서를 가져다대면 호출 시그니처를 알려준다
import { Equal, Expect } from '../../helper';

type LocationId = string;

const getLocationWeather = (locationId: LocationId) => {
  return `Weather at location ${locationId}`;
};
type GetLocationWeatherReturn = ReturnType<typeof getLocationWeather>;

const getDetailedWeather = (
  locationId: LocationId,
  details?: {
    tempUnit?: 'C' | 'F';
    includeForecast?: boolean;
  }
) => {};

type GetDetailedWeatherParameters = Parameters<typeof getDetailedWeather>;

type tests = [
  Expect<Equal<GetLocationWeatherReturn, string>>,
  Expect<
    Equal<
      GetDetailedWeatherParameters,
      [
        locationId: LocationId,
        details?:
          | {
              tempUnit?: 'C' | 'F' | undefined;
              includeForecast?: boolean | undefined;
            }
          | undefined
      ]
    >
  >
];
// 파라미터는 튜플로 변환된다!