Last active
March 11, 2023 17:17
-
-
Save HerringtonDarkholme/986233916909c33506f3732056f9cb5e to your computer and use it in GitHub Desktop.
repro weird ts 5.1 error
This file contains hidden or 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
type ComponentPublicInstance<C, Options> = { | |
$options: Options & 'intersection anything' | |
} & ExtractComputedReturns<C> | |
type WhatEver<T> = T extends 1 ? true : false | |
type MixinToOptionTypes<T> = T extends ComponentOptionsBase< | |
infer C, 1, 1 | |
> | |
? OptionTypesType<C> | |
: never | |
type IntersectionMixin<T> = WhatEver<T> extends true | |
? OptionTypesType<{}> | |
: MixinToOptionTypes<T> | |
type CreateComponentPublicInstance< | |
Mixin extends 1 , | |
Extends extends 1, | |
> = ComponentPublicInstance< | |
(IntersectionMixin<Mixin> & IntersectionMixin<Extends>)['C'], | |
ComponentOptionsBase<{}, Mixin, Extends> | |
> | |
interface ComponentOptionsBase< | |
_C extends ComputedOptions, | |
Mixin extends 1, | |
Extends extends 1, | |
> { | |
data?: ( | |
this: CreateComponentPublicInstance< | |
Mixin, | |
Extends | |
>, | |
) => {} | |
} | |
type ComputedGetter = (...args: any[]) => any | |
type ComputedOptions = Record< | |
string, | |
ComputedGetter | {get: ComputedGetter } | |
> | |
type ExtractComputedReturns<T extends any> = { | |
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn } | |
? TReturn | |
: T[key] extends (...args: any[]) => infer TReturn | |
? TReturn | |
: never | |
} | |
type OptionTypesType<C = {}> = { C: C } | |
type Mixin = 1; type Extend = 1; | |
type A1 = ComponentOptionsBase<any,Mixin,Extend> &{sth?:never} | |
export type Test1 = A1 extends ComponentOptionsBase<any,any,any>?'yes':'no' | |
// ^? | |
type A2 = ComponentOptionsBase<any,Mixin,Extend> | |
export type Test2 = A2 extends ComponentOptionsBase<any,any,any>?'yes':'no' | |
// ^? | |
type A3 = ComponentOptionsBase<any,Mixin,any> &{sth?:never} | |
export type Test3 = A3 extends ComponentOptionsBase<any,any,any>?'yes':'no' | |
// ^? | |
type A4 = ComponentOptionsBase<any,any,Extend> &{sth?:never} | |
export type Test4 = A4 extends ComponentOptionsBase<any,any,any>?'yes':'no' | |
// ^? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment