Skip to content

Commit

Permalink
fix: missing type imports (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed Mar 11, 2024
1 parent f3c0df2 commit 63681a6
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-keys-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

Fix a couple of type imports issues in .d.ts files
4 changes: 3 additions & 1 deletion lib/buildFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import createFormatArgs from './utils/createFormatArgs.js';
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
* @typedef {import('../types/Config.d.ts').Config} Config
* @typedef {import('../types/File.d.ts').File} File
* @typedef {import('../types/Filter.d.ts').Matcher} Matcher
*/

/**
Expand All @@ -37,7 +38,8 @@ import createFormatArgs from './utils/createFormatArgs.js';
* @param {Config} options
*/
export default async function buildFile(file, platform = {}, dictionary, options) {
const { destination, filter } = file || {};
const { destination } = file || {};
const filter = /** @type {Matcher|undefined} */ (file.filter);
let { format } = file || {};

if (typeof format !== 'function') throw new Error('Please enter a valid file format');
Expand Down
6 changes: 3 additions & 3 deletions lib/common/formatHelpers/getTypeScriptType.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
* });
*```
* @param {any} value A value to check the type of.
* @param {Options & Config & {outputStringLiterals?: boolean}} [options]
* @param {Config & {outputStringLiterals?: boolean}} [options]
* @return {String} A valid name for a TypeScript type.
*
*/
export default function getTypeScriptType(value, options = {}) {
const { outputStringLiterals = false } = options;
export default function getTypeScriptType(value, options) {
const { outputStringLiterals = false } = options ?? {};

if (Array.isArray(value)) return getArrayType(value);
if (typeof value === 'object') return getObjectType(value);
Expand Down
2 changes: 1 addition & 1 deletion lib/common/formatHelpers/iconsWithPrefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
* @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
* @typedef {import('../../../types/Config.d.ts').Config} Options
* @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/common/formatHelpers/setComposeObjectProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Outputs an object for compose format configurations. Sets import.
* @memberof module:formatHelpers
* @name setComposeObjectProperties
* @param {Options & {import?:string[]}} [options] - The options object declared at configuration
* @param {{import?:string[]}} [options] - The options object declared at configuration
* @returns {Object}
*/
export default function setComposeObjectProperties(options = {}) {
Expand Down
6 changes: 3 additions & 3 deletions lib/common/formatHelpers/setSwiftFileProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
* Outputs an object with swift format configurations. Sets import, object type and access control.
* @memberof module:formatHelpers
* @name setSwiftFileProperties
* @param {Options & {objectType?:string; import?: string[]; accessControl?: string;}} [options] - The options object declared at configuration
* @param {{objectType?:string; import?: string[]; accessControl?: string;}} options - The options object declared at configuration
* @param {String} [objectType] - The type of the object in the final file. Could be a class, enum, struct, etc.
* @param {String} [transformGroup] - The transformGroup of the file, so it can be applied proper import
* @returns {Object}
*/
export default function setSwiftFileProperties(options = {}, objectType, transformGroup) {
if (typeof options.objectType === 'undefined') {
export default function setSwiftFileProperties(options, objectType, transformGroup) {
if (options.objectType == null) {
if (typeof objectType === 'undefined') {
options.objectType = 'class';
} else {
Expand Down
7 changes: 4 additions & 3 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ const formats = {
* $color-background-alt= #eeeeee;
* ```
*/
'stylus/variables': async function ({ dictionary, options, file }) {
const { outputReferences, usesDtcg } = options;
'stylus/variables': async function ({ dictionary, options, file, platform }) {
const { usesDtcg } = options;
const outputReferences = !!platform.options?.outputReferences;
const header = await fileHeader({ file, commentStyle: 'short' });
return (
header +
Expand Down Expand Up @@ -547,7 +548,7 @@ const formats = {
*
* @memberof Formats
* @kind member
* @param {FormatOpts} options
* @param {FormatOpts & { options: { moduleName?: string }}} options
* @example
* ```typescript
* export default tokens;
Expand Down
2 changes: 1 addition & 1 deletion lib/filterTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function filterTokenObject(tokens, filter, options) {
* object using a function provided by the user.
*
* @param {Dictionary} dictionary
* @param {Matcher} filter - A function that receives a token object
* @param {Matcher} [filter] - A function that receives a token object
* and returns `true` if the token should be included in the output
* or `false` if the token should be excluded from the output
* @param {Config} [options]
Expand Down
2 changes: 1 addition & 1 deletion lib/transform/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ None of ${transform_warnings} match the name of a registered transform.

to_ret.files = (to_ret.files || []).map(function (file) {
const ext = /** @type {File} */ ({ options: {} });
if (file.options && file.options.fileHeader) {
if (file.options && file.options.fileHeader && ext.options) {
const fileHeader = file.options.fileHeader;
if (typeof fileHeader === 'string') {
if (dictionary.fileHeader[fileHeader]) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/createFormatArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import deepExtend from './deepExtend.js';
/**
* @typedef {import('../../types/DesignToken.js').Dictionary} Dictionary
* @typedef {import('../../types/Config.d.ts').PlatformConfig} PlatformConfig
* @typedef {import('../../types/Config.d.ts').Config} Config
* @typedef {import('../../types/Config.d.ts').Config} Options
* @typedef {import('../../types/File.d.ts').File} File
*
Expand All @@ -25,7 +25,7 @@ import deepExtend from './deepExtend.js';
* @param {{
* dictionary: Dictionary;
* platform: PlatformConfig;
* options: Config;
* options: Options;
* file: File;
* }} param0
* @returns
Expand Down
2 changes: 2 additions & 0 deletions types/File.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { TransformedToken } from './DesignToken.d.ts';
import type { Formatter } from './Format.d.ts';
import type { LocalOptions } from './Config.d.ts';
import type { Matcher } from './Filter.d.ts';

export interface FormattingOptions {
prefix?: string;
Expand Down
5 changes: 2 additions & 3 deletions types/Format.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

import type { Dictionary } from './DesignToken.d.ts';
import type { File } from './File.d.ts';
import type { LocalOptions, Config } from './Config.d.ts';
import type { PlatformConfig } from './Platform.d.ts';
import type { LocalOptions, Config, PlatformConfig } from './Config.d.ts';

export interface FormatterArguments {
/**
Expand All @@ -28,7 +27,7 @@ export interface FormatterArguments {
/**
* The options object,
*/
options: LocalOptions & Config;
options: Config & LocalConfig;
/**
* The platform configuration the format is called in
*/
Expand Down

0 comments on commit 63681a6

Please sign in to comment.