amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.87k stars 543 forks source link

How to access FormatterArguments types, etc. #1135

Closed lukasoppermann closed 5 months ago

lukasoppermann commented 6 months ago

Hey @jorenbroekema,

I have no idea how to access some types, like FormatterArguments.

They are not exported from style-dictionary/types and also not available through something like Format['FormatterArguments'].

The way you use it in here, seems to not be typical typescript, so can you help me find out how I can access those types? Thanks.

One of the places where I have this issue is here: https://github.com/lukasoppermann/style-dictionary-utils/pull/65/files#diff-4c8b203eb592cb0973b6227b4be99616520e7b0351981b54dfbd320fd0aa117aR3

jorenbroekema commented 6 months ago

Hmm I think I should consider exporting all types inside our types directory instead of only the main interfaces.

PRs very welcome to adjust https://github.com/amzn/style-dictionary/blob/v4/types/index.d.ts and export all from all sibling .d.ts files (Volume.d.ts is new, should be added as well)

jorenbroekema commented 6 months ago

Cool trick you can do as well:

import type { Format } from 'style-dictionary/types';

type FormatterArguments = Parameters<Format['formatter']>;
lukasoppermann commented 6 months ago

Somehow for me using this "trick" I don't get ts autocomplete or suggestions.

lukasoppermann commented 6 months ago

PR is up: https://github.com/amzn/style-dictionary/pull/1137

Hope this is what you meant.

jorenbroekema commented 6 months ago

Works for me. Since style-dictionary uses package entrypoints your tsconfig compilerOptions needs "module": "nodenext" and "moduleResolution": "nodenext" or "moduleResolution": "bundler" if you need it e.g. extensionless imports, otherwise it won't be able to find the declarations

image