microsoft / microsoft/TypeScript
Strange intersection/variance behavior
Abierto
@weswigham ya está trabajando en esto.
Desde el 25/8/2020.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
TypeScript Version: Nightly (d6dda230bce0828144e5f17539d6e3f9bf4c4f3b)
Search Terms: variance, intersection
Code
interface BaseEvent {
type: string;
}
interface DerivedEvent extends BaseEvent {
type: "mytype";
payload: number;
};
type TransitionConfig<TEvent extends BaseEvent> = (event: TEvent) => void;
type TransitionsConfigMap<TEvent extends BaseEvent> =
& { splendiferous?: never } // Un/comment this line
& { [K in TEvent['type']]?: TransitionConfig<TEvent>; };
type TransitionsConfigArray<TEvent extends BaseEvent> = {
[K in TEvent['type']]: TransitionConfig<TEvent extends { type: K; } ? TEvent : never>;
}[TEvent['type']];
type AssignAction<TEvent extends BaseEvent> = (meta: TransitionsConfigMap<TEvent> | TransitionsConfigArray<TEvent>) => void;
declare const d1: AssignAction<DerivedEvent>;
declare const b1: AssignAction<BaseEvent>;
const d2: typeof d1 = b1; // Sometimes an error
const b2: typeof b1 = d1; // Sometimes an error
As-is, there are errors on both d2 and b2. If you comment out the "splendiferous" line, the error on b2 goes away. (If you disable strict function types, the error on d2 also goes away.) I find this strange, since that line does not reference TEvent.
The type names give breadcrumbs back into xstate, but I've inlined and deleted so many things that the structure is substantially different.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.