-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Search Terms
infer
Suggestion
Add the possibility to type a variable with const myValue: infer = complexThing;
Use Cases
This solves the problem of having to disable the line with eslint/tslint if the rule typedef is intentionally activated
Examples
(only one example)
I have created a very complex smart class that deeply infers column-names for a table.
The class member table is now a very huge type and therefore I dont want to type it.
But I also dont want to write table: any or table: unknown
Details
@Component
export default class MyVueComponent {
// eslint-disable-next-line @typescript-eslint/typedef
public readonly table = new DataTable({
// ~~ dont want it to be any or unknown
columnDefinitions: [
{
name: 'id',
text: this.$t('table.id'),
align: 'end',
sortable: true,
width: 120
},
{
name: 'value',
text: this.$t('table.value'),
sortable: true,
width: 250
},
{
name: 'type',
text: this.$t('table.type'),
sortable: true,
width: 150
},
{
name: 'synonyms',
text: this.$t('table.synonyms'),
sortable: false
},
{
name: 'link',
text: this.$t('table.link'),
sortable: true,
width: 90,
hideable: true,
guard: () => this.$auth.isDeveloper()
},
{
name: 'linkApproved',
text: this.$t('table.link-approved'),
sortable: true,
width: 140,
hideable: true,
guard: () => this.$auth.isDeveloper()
},
{
name: 'modifiedAt',
text: this.$t('table.modified-at'),
sortable: true,
width: 150,
hideable: true
},
{
name: 'textAdUsage',
text: this.$t('table.text-ad-usage'),
sortable: true,
width: 150,
hideable: true
},
{
name: 'group',
text: this.$t('table.entity-group'),
sortable: true,
width: 140,
hideable: true
},
{
name: 'relation',
text: this.$t('table.relation-to'),
sortable: true,
width: 170,
hideable: true
},
{
name: 'standalone',
text: this.$t('table.standalone'),
sortable: true,
width: 180,
hideable: true
},
{
name: 'textAdAlternative',
text: this.$t('table.text-ad-alternative'),
sortable: true,
width: 170,
hideable: true
},
{
name: 'actions',
text: this.$t('global.table.header.actions'),
width: 120
}
]
});
}eslint blames me about to add a typedef to this line.
- I dont want to write the complete typedef to
tableand want the behaviour as not writing a typedef. - I want to signalise other developers that this is fully intended and want the behaviour.
So I can still profit of it when calling a function of it likethis.table.setColumnVisibility('link', false);, were the first parameter is an union string literal of all possible hidden columns!
We cant create a type or interface with the name infer and use it as type definition
Therefore this will not be a breaking change!
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
ilogico
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
