BenjaminO Posted November 5, 2022 Share Posted November 5, 2022 I have the following typescript errors for isMobile and isDesktop in gsap.matchMedia(): const isDesktop: any property 'isDesktop' doesn't exists on type 'Conditions | undefined'.ts(2339) const mm = gsap.matchMedia() mm.add( { isMobile: '(max-width: 766px)', isDesktop: '(min-width: 767px)' }, (context) => { const { isMobile, isDesktop } = context.conditions // error ts 2339 } ) Link to comment Share on other sites More sharing options...
Rodrigo Posted November 5, 2022 Share Posted November 5, 2022 Hi I'm far from being a TS expert or even competent at it, but in your code snippet where are you passing the types declaration for isMobile and isDesktop? Those should be booleans as far as I can tell. Right now I'm using my phone so I can't check, but I'm pretty sure that you can create a TS example in either codesanbox or replit.com and set up a minimal demo that we can take a look at. Happy Tweening! Link to comment Share on other sites More sharing options...
GreenSock Posted November 5, 2022 Share Posted November 5, 2022 @BenjaminO that is typed like this in the definitions file: interface Conditions { [key: string]: boolean; } Which as I understand it allows for ANY key. Am I missing something? I'm not aware of any other way to do this, but let us know if you have a suggestion. Keep in mind that isDesktop and isMobile are completely arbitrary names - users can pick any name they want for any condition, so we cannot pre-define any particular names on the Conditions object. 1 Link to comment Share on other sites More sharing options...
BenjaminO Posted November 6, 2022 Author Share Posted November 6, 2022 I think the problem is related to the interface Context below : interface Context { [key: string]: any; selector?: Function; isReverted: boolean; conditions?: Conditions; // no problem without the ? queries?: object; add(methodName: string, func: Function, scope?: Element | string | object): Function; add(func: Function, scope?: Element | string | object): void; ignore(func: Function): void; kill(revert?: boolean): void; revert(config?: object): void; clear(): void; } The thing is that the different conditions (isMobile, isDesktop in my case) are typed ANY because they inherit from a union type of gsap.Conditions | undefined because of the ?. The undefined type is causing the error here so conditions should be mandatory IMHO. Link to comment Share on other sites More sharing options...
Solution BenjaminO Posted November 6, 2022 Author Solution Share Posted November 6, 2022 After digging a bit I found out that declaring the type explicitly was doing the job here 🙂 const { isMobile, isDesktop } = context.conditions as gsap.Conditions 3 Link to comment Share on other sites More sharing options...
GreenSock Posted November 7, 2022 Share Posted November 7, 2022 17 hours ago, BenjaminO said: so conditions should be mandatory IMHO No, it can't be because there are various scenarios where there is no conditions object. Sorry. But I'm glad you found a way to make it work in your environment. 👍 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now