Skip to content
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

typescript: token function typings #18

Closed
dsvgl opened this issue Nov 22, 2022 · 1 comment
Closed

typescript: token function typings #18

dsvgl opened this issue Nov 22, 2022 · 1 comment

Comments

@dsvgl
Copy link

dsvgl commented Nov 22, 2022

Hello, it's me again 😆

your latest fix to #17 doesn't work as expected.

I doesn't complains about mode as second argument needed anymore. Great.

But I don't get intellisense for mode (tested with your apple example):
SCR-20221122-o6x

Also, I can put anything in both slots:
SCR-20221122-o79

@drwpow
Copy link
Collaborator

drwpow commented Jan 29, 2023

Hello! I just fixed a TS error related to the token() function.

For your first problem, I’m not sure if intellisense is able to auto-fill the value. Sadly, you’ll just have to provide the value yourself, but it can tell you if the types don’t match.

For the 2nd problem—“no error”—I fixed a bug where it should throw a type error if you are trying to access a mode that doesn’t exist. Note that the signatures will have to match exactly, e.g.:

const mode = 'light'; // auto-cast as `string`
token('color.foreground', mode); // ❌ expecting `'light' | 'dark'`

const mode: 'light' | 'dark' = 'light';
token('color.foreground', mode); // ✅

In regards to runtime errors, however, it’s by design that this won’t throw a runtime error; it will just fall back to whatever the default value is. This is probably more generally useful, as tokens are meant to sometimes omit modes when they don’t need them.

@drwpow drwpow closed this as completed Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants