types.ts
types.ts copied to clipboard
Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters'] gives broken types in version newer than v6.3.2
How to recreate the issue
Exactly same issues as: https://github.com/octokit/types.ts/issues/274
Create a test project:
npm init -y && npm install typescript @octokit/types
Generates this package.json file:
{
"name": "test-repo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@octokit/types": "^6.11.0",
"typescript": "^4.2.2"
}
}
Create test.ts:
import { Endpoints } from '@octokit/types'
type listUserReposParameters = Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters']
const test: listUserReposParameters = {
name: '',
head_sha: '',
owner: '',
repo: '',
status: 'completed'
}
./node_modules/.bin/tsc test.ts
Gives the following error and the type that it constructed seems very broken:
test.ts:10:5 - error TS2322: Type 'string' is not assignable to type 'never'.
10 status: 'completed'
~~~~~~
node_modules/@octokit/openapi-types/dist-types/generated/types.d.ts:19876:21
19876 status?: "completed";
~~~~~~
The expected type comes from property 'status' which is declared here on type '{ owner: string; repo: string; check_run_id: number; } & Partial<{ status?: "completed"; } & { [key: string]: any; }> & Partial<{ status?: "queued" | "in_progress"; } & { [key: string]: any; }> & { ...; }'
Found 1 error.
Trying with v6.3.2 works:
npm install @octokit/[email protected]
tsc test.ts
Diff is here: https://github.com/octokit/types.ts/compare/v6.3.2...v6.4.0
hmm sorry for that, I thought we had the problem with the status parameter resolved. By the way you could have reopened #274 in this case, but either works
By the way you could have reopened #274 in this case, but either works
ah sorry I see now it's a different path, I got it
reported the problem here: https://github.com/github/rest-api-description/issues/228. Once resolved in https://github.com/github/rest-api-description, @octokit/types will get updated shortly after by our bots
The original problem was resolved at github/rest-api-description#228, but now status type is set to undefined. It's now likely a problem in how we transpile the OpenAPI spec to TypeScript, I'll have a look
I'm also hitting this issue with "@octokit/core": "^4.2.1" and "@octokit/types": "^9.2.3".
import { Octokit } from '@octokit/core';
import { Endpoints } from '@octokit/types';
export async function updateStatusCheck(
octokit: Octokit,
checkID: number,
status: Endpoints['POST /repos/{owner}/{repo}/check-runs']['parameters']['status'],
conclusion: Endpoints['POST /repos/{owner}/{repo}/check-runs']['parameters']['conclusion'],
message: string
) {
await octokit.request(
'PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}',
{
check_run_id: checkID,
status,
completed_at: new Date().toISOString(),
conclusion,
output: {
title: 'Validation Status',
summary: message,
},
}
);
}
Both status and conclusion has mismatched types.
Type '"queued" | "in_progress" | "completed" | undefined' is not assignable to type 'undefined'. Type '"queued"' is not assignable to type 'undefined'.ts(2322)
Type 'unknown' is not assignable to type '"action_required" | "cancelled" | "failure" | "neutral" | "success" | "skipped" | "stale" | "timed_out" | undefined'.ts(2322)
@tlbdk @jamacku Can you reproduce this issue with the latest version?
@wolfy1339 The status type is fixed, but the conclusion is still emitting the same error message.
Type 'unknown' is not assignable to type '"action_required" | "cancelled" | "failure" | "neutral" | "success" | "skipped" | "stale" | "timed_out" | undefined'.
@wolfy1339, I can't reproduce this issue with the latest version: "@octokit/types": "^12.0.0". It's fixed for me. Thank you.