@@ -12,7 +12,11 @@ export interface Job {
1212 created_at : string ;
1313 started_at : string | null ;
1414 ended_at : string | null ;
15- tasks : Task [ ] ;
15+ tasks : JobTask [ ] ;
16+ }
17+ type NotPresentWhenInsideJob = 'job_id'
18+ interface JobTask extends Omit < Task , NotPresentWhenInsideJob > {
19+ name : string ;
1620}
1721
1822export default class JobsResource {
@@ -42,7 +46,7 @@ export default class JobsResource {
4246 }
4347
4448 // See below for an explanation on how this type signature works
45- async create ( data : { tasks : TaskContainer } | null = null ) : Promise < Job > {
49+ async create ( data : JobTemplate | null = null ) : Promise < Job > {
4650 const response = await this . cloudConvert . axios . post ( 'jobs' , data ) ;
4751 return response . data . data ;
4852 }
@@ -75,12 +79,15 @@ interface NamedOperation<O> { operation: O }
7579type OperationByName < O > = Extract < Operation , NamedOperation < O > >
7680// Given an operation string O, get the operation data for it
7781type OperationData < O > = OperationByName < O > [ 'data' ] ;
82+ // Add all properties to task that can only occur in tasks that are inside jobs
83+ interface TaskExtras < O > extends NamedOperation < O > { ignore_error ?: boolean ; }
7884// Every argument in the tasks object is typed by this (for some operation string O)
79- type TaskTemplate < O > = NamedOperation < O > & OperationData < O > ;
85+ type TaskTemplate < O > = TaskExtras < O > & OperationData < O > ;
8086// Given a union type U of operation strings, turn each operation string into its TaskTemplate
8187type Distribute < U > = U extends any ? TaskTemplate < U > : never ;
8288// Create a union of all possible tasks
8389type PossibleOperations = Distribute < PossibleOperationStrings > ;
8490// Allow any number of names, each typed by a possible operation
8591interface TaskContainer { [ name : string ] : PossibleOperations ; }
86- // Yay! We can now use this container for our function signature above.
92+ // Add the other properties that are required for job creation
93+ interface JobTemplate { tasks : TaskContainer ; tag ?: string ; }
0 commit comments