-
Notifications
You must be signed in to change notification settings - Fork 336
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
Custom component configs cause TypeScript compiler errors #5606
Comments
Looks like the compiler error would be triggered by the existing components too Fixed keys like Type 'ExampleConfig' does not satisfy the constraint 'ObjectNested'.
Index signature for type 'string' is missing in type 'ExampleConfig'. ts(2344) Might be a better idea to use - * @template {ObjectNested} [ConfigurationType={}]
+ * @template {Record<keyof ConfigurationType, unknown>} [ConfigurationType=ObjectNested] |
I've applied the same fixes as #5607 to DefinitelyTyped/DefinitelyTyped@d3b7de6 for |
Cheers for the issue and the attempt at fixing this 😊 I'm trying to wrap my head around what's going on so I can follow what the fix does, but our type linting seems to work OK with both:
Could please you provide a little more details about:
/**
* @augments ConfigurableComponent<ExampleConfig>
*/
class ExampleComponent extends ConfigurableComponent {
static defaults = {
anOption: 'aValue'
}
static schema = {
properties: {
anOption: { type: 'string' }
}
}
}
/**
* @typedef {object} ExampleConfig
* @property {string} anOption
*/ Cheers 😊 |
Yeah course, give one of these examples a try Any custom config that doesn't meet Nullable option valuesE.g. Using /**
* @typedef {object} ExampleConfig
* @property {string?} anOption - Nullable strings are not allowed
*/ Array option values/**
* @typedef {object} ExampleConfig
* @property {string} anOption - Strings are allowed
* @property {string[]} brokenOption1 - Arrays of strings not allowed
* @property {{ text: string }[]} brokenOption2 - Arrays of objects not allowed
*/ Strict literal option valuesIn TypeScript only, string literal (and string enum) values cause errors type ExampleConfig = {
/**
* String literals are not allowed
*/
brokenOption: 'red' | 'blue'
} Options with only known keysIn TypeScript only, all configs that don't extend type ExampleConfig = {
+ [key: string]: string
anOption: string
} This is because all configs must match It prevents unknown or legacy properties like |
Did you notice that Flipping the tsconfig.json reference order fixes it: {
"extends": "../../tsconfig.base.json",
"files": [],
"references": [
{
- "path": "./tsconfig.dev.json"
+ "path": "./tsconfig.build.json"
},
{
- "path": "./tsconfig.build.json"
+ "path": "./tsconfig.dev.json"
}
]
} Wonder if this was a recent TypeScript compiler change? |
In short, I've swapped This allows users with type checking enabling to create their own configs as they wish |
Description of the issue
Hello 👋
Nice work with the v5.8.0 release! Mind if I raise a little JSDoc types issue?
In TypeScript projects, the compiler outputs this error for
ConfigurableComponent
configs:Similarly, config properties can't use use arrays or have
null
values asObjectNested
doesn't support themSteps to reproduce the issue
Configure tsconfig.json to include GOV.UK Frontend sources or use
@types/govuk-frontend
(generated via JSDoc)Actual vs expected behaviour
I've had a look, and the JSDoc is set up to only accept
string | boolean | number
or other nested objects as allowed properties as part of theObjectNested
definitionDo you think component configs should allow
ObjectNested
{ [key: string]: unknown }
instead?Happy to give a PR a go
The text was updated successfully, but these errors were encountered: