-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit declarations using alternative containing modules for types exported using separate export statements #56857
Merged
weswigham
merged 2 commits into
microsoft:main
from
Andarist:fix/dts-emit-through-separate-export-statements
Jan 9, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
273 changes: 273 additions & 0 deletions
273
tests/baselines/reference/declarationEmitUsingAlternativeContainingModules1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,273 @@ | ||
//// [tests/cases/compiler/declarationEmitUsingAlternativeContainingModules1.ts] //// | ||
|
||
//// [useQuery-CPqkvEsh.d.ts] | ||
type QueryKey = ReadonlyArray<unknown>; | ||
|
||
interface Register {} | ||
|
||
type DefaultError = Register extends { | ||
defaultError: infer TError; | ||
} | ||
? TError | ||
: Error; | ||
|
||
type ShouldRetryFunction<TError = DefaultError> = ( | ||
failureCount: number, | ||
error: TError, | ||
) => boolean; | ||
type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>; | ||
|
||
type QueryFunctionContext< | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = never, | ||
> = [TPageParam] extends [never] | ||
? { | ||
queryKey: TQueryKey; | ||
} | ||
: { | ||
queryKey: TQueryKey; | ||
pageParam: TPageParam; | ||
}; | ||
|
||
type QueryFunction< | ||
T = unknown, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = never, | ||
> = (context: QueryFunctionContext<TQueryKey, TPageParam>) => T | Promise<T>; | ||
|
||
interface QueryOptions< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = never, | ||
> { | ||
retry?: RetryValue<TError>; | ||
queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam>; | ||
queryKey?: TQueryKey; | ||
initialData?: TData; | ||
initialDataUpdatedAt?: number | (() => number | undefined); | ||
} | ||
|
||
interface QueryObserverOptions< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
TData = TQueryFnData, | ||
TQueryData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = never, | ||
> extends QueryOptions< | ||
TQueryFnData, | ||
TError, | ||
TQueryData, | ||
TQueryKey, | ||
TPageParam | ||
> { | ||
enabled?: boolean; | ||
refetchInterval?: number; | ||
select?: (data: TQueryData) => TData; | ||
} | ||
|
||
type UseQueryOptions< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
TData = TQueryFnData, | ||
TQueryData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
> = { | ||
[Property in keyof QueryObserverOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryData, | ||
TQueryKey | ||
>]: QueryObserverOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryData, | ||
TQueryKey | ||
>[Property]; | ||
}; | ||
|
||
type UndefinedInitialQueryOptions< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & { | ||
initialData?: undefined; | ||
}; | ||
|
||
interface QueryObserverBaseResult<TData = unknown, TError = DefaultError> { | ||
data: TData | undefined; | ||
dataUpdatedAt: number; | ||
error: TError | null; | ||
errorUpdatedAt: number; | ||
failureCount: number; | ||
failureReason: TError | null; | ||
errorUpdateCount: number; | ||
isError: boolean; | ||
isFetched: boolean; | ||
isFetchedAfterMount: boolean; | ||
isFetching: boolean; | ||
isLoading: boolean; | ||
isPending: boolean; | ||
isLoadingError: boolean; | ||
isInitialLoading: boolean; | ||
isPaused: boolean; | ||
isPlaceholderData: boolean; | ||
isRefetchError: boolean; | ||
isRefetching: boolean; | ||
isStale: boolean; | ||
isSuccess: boolean; | ||
} | ||
|
||
interface QueryObserverSuccessResult<TData = unknown, TError = DefaultError> | ||
extends QueryObserverBaseResult<TData, TError> { | ||
data: TData; | ||
error: null; | ||
isError: false; | ||
isPending: false; | ||
isLoadingError: false; | ||
isRefetchError: false; | ||
isSuccess: true; | ||
status: "success"; | ||
} | ||
|
||
type DefinedQueryObserverResult< | ||
TData = unknown, | ||
TError = DefaultError, | ||
> = QueryObserverSuccessResult<TData, TError>; | ||
type QueryObserverResult< | ||
TData = unknown, | ||
TError = DefaultError, | ||
> = DefinedQueryObserverResult<TData, TError>; | ||
|
||
type ToRef<T> = { | ||
value: T; | ||
}; | ||
|
||
type UseBaseQueryReturnType< | ||
TData, | ||
TError, | ||
Result = QueryObserverResult<TData, TError>, | ||
> = { | ||
[K in keyof Result]: K extends | ||
| "fetchNextPage" | ||
| "fetchPreviousPage" | ||
| "refetch" | ||
? Result[K] | ||
: ToRef<Readonly<Result>[K]>; | ||
} & { | ||
suspense: () => Promise<Result>; | ||
}; | ||
|
||
type UseQueryReturnType<TData, TError> = UseBaseQueryReturnType<TData, TError>; | ||
|
||
declare function useQuery< | ||
TQueryFnData = unknown, | ||
TError = DefaultError, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
>( | ||
options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | ||
): UseQueryReturnType<TData, TError>; | ||
|
||
export { type UseQueryReturnType, useQuery }; | ||
|
||
//// [index.d.ts] | ||
export { UseQueryReturnType, useQuery } from './useQuery-CPqkvEsh.js'; | ||
|
||
//// [package.json] | ||
{ | ||
"name": "@tanstack/vue-query", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./build/modern/index.d.ts", | ||
"default": "./build/modern/index.js" | ||
}, | ||
"require": { | ||
"types": "./build/modern/index.d.cts", | ||
"default": "./build/modern/index.cjs" | ||
} | ||
} | ||
} | ||
} | ||
|
||
//// [index.mts] | ||
import { useQuery } from '@tanstack/vue-query' | ||
|
||
const baseUrl = 'https://api.publicapis.org/' | ||
|
||
interface IEntry { | ||
API: string | ||
Description: string | ||
Auth: string | ||
HTTPS: boolean | ||
Cors: string | ||
Link: string | ||
Category: string | ||
} | ||
|
||
const testApi = { | ||
getEntries: (): Promise<IEntry[]> => { | ||
return fetch(baseUrl + 'entries') | ||
.then((res) => res.json()) | ||
.then((data) => data.entries) | ||
.catch((err) => console.log(err)) | ||
} | ||
} | ||
|
||
const entryKeys = { | ||
all: ['entries'] as const, | ||
list: () => [...entryKeys.all, 'list'] as const | ||
} | ||
|
||
export const useEntries = () => { | ||
return useQuery({ | ||
queryKey: entryKeys.list(), | ||
queryFn: testApi.getEntries, | ||
select: (data) => data.slice(0, 10) | ||
}) | ||
} | ||
|
||
|
||
//// [index.mjs] | ||
import { useQuery } from '@tanstack/vue-query'; | ||
const baseUrl = 'https://api.publicapis.org/'; | ||
const testApi = { | ||
getEntries: () => { | ||
return fetch(baseUrl + 'entries') | ||
.then((res) => res.json()) | ||
.then((data) => data.entries) | ||
.catch((err) => console.log(err)); | ||
} | ||
}; | ||
const entryKeys = { | ||
all: ['entries'], | ||
list: () => [...entryKeys.all, 'list'] | ||
}; | ||
export const useEntries = () => { | ||
return useQuery({ | ||
queryKey: entryKeys.list(), | ||
queryFn: testApi.getEntries, | ||
select: (data) => data.slice(0, 10) | ||
}); | ||
}; | ||
|
||
|
||
//// [index.d.mts] | ||
interface IEntry { | ||
API: string; | ||
Description: string; | ||
Auth: string; | ||
HTTPS: boolean; | ||
Cors: string; | ||
Link: string; | ||
Category: string; | ||
} | ||
export declare const useEntries: () => import("@tanstack/vue-query").UseQueryReturnType<IEntry[], Error>; | ||
export {}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is ad-hoc, perhaps I should just
flatMap
this. From what I've seen the consumers of this return value assume some ordering - or well, operate on first items with priority or smth. So I'm not sure how it would behave in more complex scenarios with smth like:[...withAlternativeContainersA, ...withAlternativeContainersB, ...withAlternativeContainersC]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait I’m confused; why would there only being a single element in the array affect whether you need to repackage it or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to explain this in the comment above. This is the only case I know how to reason about and about which i’m somewhat confident here. This is not the final solution - i’m seeking guidance what should be done here when there are more items in this array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the results returned here are intended to be in priority order for "what is best to serialize", which is, admittedly, a bit subjective. IMO, the ordering here would probably be the direct symbols for each available container symbol, followed by all their alternative symbols, in order - so not quite a flat map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented the suggested solution. Could you take another look?