microsoft / microsoft/TypeScript
instantiation expression usage leading to an invalid d.ts file generation
@weswigham ci sta già lavorando.
Dal 13/12/2024.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
partial function generic application, function generic variant from another function, instantiation-expressions
🕗 Version & Regression Information
- This changed between versions 5.6.2 and 5.7.2
⏯ Playground Link
💻 Code
type SomePropertyKeys = ReadonlyArray<PropertyKey>
type At<A extends ReadonlyArray<unknown>, I extends number = number> = A[I]
export function mainKeyGuard<
K extends readonly [PropertyKey, ...SomePropertyKeys],
>(
keys: K,
): <T extends object>(
value: T,
) => value is Extract<T, Record<At<K, 0>, unknown>> {
return <T extends object>(
value: T,
): value is Extract<T, Record<At<K, 0>, unknown>> => {
return keys[0] in value
}
}
type Foo = { foo1: string, foo2: string }
type Bar = { bar1: string, bar2: string }
type FooBar = Foo | Bar
const barKeys = ['bar1', 'bar2'] as const
export const isBar = mainKeyGuard(barKeys)<FooBar>
🙁 Actual behavior
Starting with the v5.7.2, the generated d.ts file declares isBar as a function which reference a missing generic type T, so an error is raised
export declare const isBar: (value: FooBar) => value is Extract<T, Record<At<K, 0>, unknown>>;
🙂 Expected behavior
I would expect the isBar function d.ts declaration to not reference a missing generic type T.
Previously, the generated d.ts file behaved like the following
export declare const isBar: (value: FooBar) => value is Bar;
Additional information about the issue
The title mentions "instantiation expression" but I'm not totally sure about how the involved feature is actually named
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.