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

styles Second argument passed into a variable object the type cannot be determined #292

Closed
fslflame opened this issue Apr 12, 2024 · 5 comments

Comments

@fslflame
Copy link

image

@fslflame
Copy link
Author

image
The example is wrong. It's vars

@zoy-l
Copy link
Collaborator

zoy-l commented Apr 15, 2024

image The example is wrong. It's vars

need to add const to the returned object, otherwise TypeScript cannot infer the specific value type.

function getStyle(){
   return {...} as const
}

@fslflame
Copy link
Author

图像这个例子是错误的。这是变量

需要给返回的对象添加const,否则TypeScript无法推断出具体的值类型。

function getStyle(){
   return {...} as const
}

Why do I need to infer to specific types that the source code has done internally?

@zoy-l
Copy link
Collaborator

zoy-l commented Apr 15, 2024

When using vars, which relies on value rather than key, the actual type obtained when using a variable is { gridTemplateColumns: string }. Therefore, it's not possible to obtain the type of a value like $grid-cols. When adding const, the type obtained is {readonly gridTemplateColumns: "$grid-cols" }.

So if the specific value $xxx cannot be obtained, vars cannot perform correct inference.

@zoy-l
Copy link
Collaborator

zoy-l commented Apr 18, 2024

I'm going to close this issue, feel free to reopen if there are any other issues

@zoy-l zoy-l closed this as completed Apr 18, 2024
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