Skip to content

Commit 8b0d98d

Browse files
author
Orta Therox
authored
Merge pull request #16 from microsoft/nightly_comment_run_fix
Adds a fix for a the first time a nightly build gets run on a comment
2 parents 697abd5 + 38a7e7e commit 8b0d98d

8 files changed

+112
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@
4242
"js-yaml": "^3.13.1",
4343
"prettier": "^2.0.5",
4444
"ts-jest": "^26.1.1",
45-
"typescript": "^4.0.0-dev.20200705"
45+
"typescript": "^4.2.0-dev.20201207"
4646
}
4747
}

scripts/getTwoslashInforForIssue.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const {getIssues} = require('../lib/getIssues')
2+
const {issueToTwoslashRun} = require('../lib/issuesToTwoslashRuns')
3+
const {runTwoslashRuns} = require('../lib/runTwoslashRuns')
4+
5+
const name = 'TypeScript'
6+
const owner = 'microsoft'
7+
const label = 'Has Repro'
8+
const tag = 'repro'
9+
10+
const issueToRun = 41617
11+
12+
const go = async () => {
13+
const ctx = {token: process.env.GITHUB_TOKEN, label, name, owner, tag}
14+
const issues = await getIssues(ctx)
15+
16+
if (issueToRun) {
17+
const issue = issues.find(i => i.number === issueToRun)
18+
const runs = issueToTwoslashRun(ctx)(issue)
19+
20+
console.log({issue})
21+
const results = runTwoslashRuns(issue, runs)
22+
console.log({results})
23+
}
24+
25+
// console.log(runs)
26+
// debugger
27+
}
28+
29+
go()

src/__tests__/fixtures/issue41617.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export const issueFixture = {
2+
id: 'MDU6SXNzdWU3NDc4MzAyNTk=',
3+
databaseId: 747830259,
4+
number: 41617,
5+
body:
6+
'**TypeScript Version:** 4.1.2\r\n\r\n**Search Terms:** CFA, narrowing, generic, mapped type, conditional type, type assertion\r\n\r\n**Code**\r\n\r\n```ts repro\r\ninterface A { x: number }\r\n\r\ndeclare function isA(a: unknown): a is A;\r\n\r\ntype FunctionsObj<T> = {\r\n [K in keyof T]: () => unknown\r\n}\r\n\r\nfunction g<\r\n T extends FunctionsObj<T>,\r\n M extends keyof T\r\n>(a2: ReturnType<T[M]>) {\r\n if (isA(a2)) {\r\n // a2 is not narrowed\r\n a2.x // error, but should be ok\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nType of `a2` should be narrowed to `ReturnType<T[M]> & A`\r\nIt works this way in TS 4.0\r\n\r\n**Actual behavior:**\r\n\r\nType of `a2` remains only `ReturnType<T[M]>`\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play?ts=4.1.0-beta#code/JYOwLgpgTgZghgYwgAgILIN7IB4C5kgCuAtgEbTIC+AUNQCYQIA2cUKMhICYwA9iMmABnVAAo4+TgGsQvAO4gAlPjiChaANy0wATwAOKAGKdufEEIDypAFYAeACoA+ZAF5M1ZMgDaAaUECpCB1eGGR7AF18UUVXZ2lZBWoaag4uHn5kAHNbDzDkCGxIEDp1YzSzSxsHRwAaXIBZfMKIYvVA4ND7akdxACZ8ACUIMEIoEHt9CAcvevDHGIxc4FDRYTE4XsUF3M8NgDpsZAB6I-yoKF4oXJoaIA\r\n',
7+
author: {login: 'Igorbek'},
8+
comments: {
9+
nodes: [
10+
{
11+
body:
12+
'I tried to reduce the repro, but it reproduces only when all these present:\r\n- conditional type that is being narrowed `ReturnType<>`\r\n- generic mapped type that is constraints by itself `T extends FunctionsObj<T>` \r\n- field accessed with generic type `T[M]`',
13+
id: 'MDEyOklzc3VlQ29tbWVudDczMjM1MjQ4MQ==',
14+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-732352481',
15+
author: {login: 'Igorbek'}
16+
},
17+
{
18+
body: '@typescript-bot run repros',
19+
id: 'MDEyOklzc3VlQ29tbWVudDczMzg1NjMxOA==',
20+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-733856318',
21+
author: {login: 'orta'}
22+
},
23+
{
24+
body:
25+
"Heya @orta, I've started to run the code sample repros for you. [Here's the link to my best guess at the log](https://github.com/microsoft/TypeScript/actions/runs/383720915).",
26+
id: 'MDEyOklzc3VlQ29tbWVudDczMzg1NjM5OA==',
27+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-733856398',
28+
author: {login: 'typescript-bot'}
29+
},
30+
{
31+
body:
32+
':wave: Hi, I\'m the [Repro bot](https://github.com/microsoft/TypeScript-Twoslash-Repro-Action/tree/master/docs/user-facing.md). I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the 2 repros in this issue running against the nightly TypeScript. If something changes, I will post a new comment.<hr />\n\n\n<tr>\n<td><a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek</td>\n<td>\n <p><p>:x: Failed: \n - <ul><li><code>Property \'x\' does not exist on type \'ReturnType&lt;T[M]>\'.</code></li></ul></p></p>\n</td>\n</tr>\n\n\n<tr>\n<td><a href=\'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738957284\'>Comment</a> by @Igorbek</a></td>\n<td>\n <p><p>:bangbang: Exception: TypeError - Cannot read property \'ES2016\' of undefined\n\n```\nTypeError: Cannot read property \'ES2016\' of undefined\n at Object.twoslasher (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:820:29)\n at /home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:3798:29\n at Array.map (<anonymous>)\n at Object.runTwoslashRuns (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:3764:43)\n at run (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:1301:43)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)\n```\n\n</p></p>\n</td>\n</tr>\n\n<details>\n <summary>Historical Information</summary>\n\n<h4><a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek</h4>\n<td>\n <table role="table">\n <thead>\n <tr>\n <th width="250">Version</th>\n <th width="80%">Reproduction Outputs</th>\n </tr>\n </thead>\n <tbody>\n \n<tr>\n<td>4.1.2, Nightly</td>\n<td>\n <p><p>:x: Failed: \n - <ul><li><code>Property \'x\' does not exist on type \'ReturnType&lt;T[M]>\'.</code></li></ul></p></p>\n</td>\n</tr>\n\n<tr>\n<td>3.7.5, 3.8.2, 3.9.2, 4.0.2</td>\n<td>\n <p><p>:+1: Compiled</p></p>\n</td>\n</tr>\n </tbody>\n </table>\n</td>\n\n\n\n<h4><a href=\'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738957284\'>Comment</a> by @Igorbek</a></h4>\n<td>\n <table role="table">\n <thead>\n <tr>\n <th width="250">Version</th>\n <th width="80%">Reproduction Outputs</th>\n </tr>\n </thead>\n <tbody>\n \n<tr>\n<td>Nightly</td>\n<td>\n <p><p>:bangbang: Exception: TypeError - Cannot read property \'ES2016\' of undefined\n\n```\nTypeError: Cannot read property \'ES2016\' of undefined\n at Object.twoslasher (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:820:29)\n at /home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:3798:29\n at Array.map (<anonymous>)\n at Object.runTwoslashRuns (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:3764:43)\n at run (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:1301:43)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)\n```\n\n</p></p>\n</td>\n</tr>\n </tbody>\n </table>\n</td>\n\n </detail>\n \n\n<!--- TypeScriptBot %%% {"runs":[{"fails":[],"assertions":[],"time":317,"label":"3.7.5","state":3,"description":"<a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek"},{"fails":[],"assertions":[],"time":309,"label":"3.8.2","state":3,"description":"<a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek"},{"fails":[],"assertions":[],"time":326,"label":"3.9.2","state":3,"description":"<a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek"},{"fails":[],"assertions":[],"time":377,"label":"4.0.2","state":3,"description":"<a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek"},{"fails":["Property \'x\' does not exist on type \'ReturnType&lt;T[M]>\'."],"assertions":[],"time":437,"label":"4.1.2","state":1,"description":"<a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek"},{"fails":["Property \'x\' does not exist on type \'ReturnType&lt;T[M]>\'."],"assertions":[],"time":329,"label":"Nightly","state":1,"description":"<a href=\'#issue-747830259\'>Issue body</a> code block by @Igorbek"},{"assertions":[],"fails":[],"exception":"TypeError - Cannot read property \'ES2016\' of undefined\\n\\n```\\nTypeError: Cannot read property \'ES2016\' of undefined\\n at Object.twoslasher (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:820:29)\\n at /home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:3798:29\\n at Array.map (<anonymous>)\\n at Object.runTwoslashRuns (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:3764:43)\\n at run (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:1301:43)\\n at processTicksAndRejections (internal/process/task_queues.js:93:5)\\n```\\n\\n","time":1,"label":"Nightly","commentID":"MDEyOklzc3VlQ29tbWVudDczODk1NzI4NA==","state":0,"description":"<a href=\'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738957284\'>Comment</a> by @Igorbek</a>"}],"commentID":"MDEyOklzc3VlQ29tbWVudDczMzg1Njc3OA==","typescriptNightlyVersion":"4.0.0-dev.20200705","typescriptSHA":"9a5c0074aa64f2a85b425b0e5e6d67c473113693"} %%% --->',
33+
id: 'MDEyOklzc3VlQ29tbWVudDczMzg1Njc3OA==',
34+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-733856778',
35+
author: {login: 'typescript-bot'}
36+
},
37+
{
38+
body:
39+
"Here's the problem, but without control flow involved:\r\n```ts repro\r\ninterface A { x: number }\r\n\r\ndeclare function isA(a: unknown): a is A;\r\n\r\ntype FunctionsObj<T> = {\r\n [K in keyof T]: () => unknown\r\n}\r\n\r\nfunction g<\r\n T extends FunctionsObj<T>,\r\n M extends keyof T\r\n>(a2: ReturnType<T[M]>, x: A) {\r\n x = a2; // shouldn't be allowed, but is\r\n}\r\n```\r\nThis is a bug in our subtyping rules, not control flow (which would undoubtedly be easier to fix).\r\n\r\n@typescript-bot run repros",
40+
id: 'MDEyOklzc3VlQ29tbWVudDczODk1NzI4NA==',
41+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738957284',
42+
author: {login: 'weswigham'}
43+
},
44+
{
45+
body:
46+
"Heya @weswigham, I've started to run the code sample repros for you. [Here's the link to my best guess at the log](https://github.com/microsoft/TypeScript/actions/runs/401332121).",
47+
id: 'MDEyOklzc3VlQ29tbWVudDczODk1NzM5Mw==',
48+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738957393',
49+
author: {login: 'typescript-bot'}
50+
},
51+
{
52+
body:
53+
'Looks like the root cause is our change in 4.1 to `isDeeplyNestedType` - it is now erroneously flagging a target side of the comparison, which doesn\'t change, as "deeply nested". Since the `source` side of the relation goes through about 6 transforms with the `target` side remaining unchanged, both sides get flagged as "deeply nesting", resulting in a `Maybe` result which eventually allows the assignment. I think this can be remedied by having separate source/target stack depths, so we don\'t increase the `target` stack depth when we\'re only transforming the `source` for a comparison.',
54+
id: 'MDEyOklzc3VlQ29tbWVudDczODk2ODA0OQ==',
55+
url: 'https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738968049',
56+
author: {login: 'weswigham'}
57+
}
58+
]
59+
}
60+
}

src/__tests__/issuesToTwoslashRuns.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {issueToTwoslashRun} from '../issuesToTwoslashRuns'
22
import {Issue} from '../getIssues'
33
import {Context} from '../getContext'
4+
import {issueFixture} from "./fixtures/issue41617"
45

56
const testCtx: Context = {
67
label: 'repro',
@@ -76,3 +77,16 @@ test('handles getting a code sample out of comments', async () => {
7677
// 2 in body, 1 in comment
7778
expect(input.codeBlocksToRun.length).toEqual(3)
7879
})
80+
81+
82+
test('handles the right names', async () => {
83+
const input = issueToTwoslashRun(testCtx)(issueFixture)
84+
// 1 in body, 1 in comment
85+
expect(input.codeBlocksToRun.length).toEqual(2)
86+
87+
const body = input.codeBlocksToRun[0]
88+
const comment = input.codeBlocksToRun[1]
89+
90+
expect(body.description).toEqual("<a href='#issue-747830259'>Issue body</a> code block by @Igorbek")
91+
expect(comment.description).toEqual("<a href='https://github.com/microsoft/TypeScript/issues/41617#issuecomment-738957284'>Comment</a> by @weswigham</a>")
92+
})

src/_main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async function run() {
2727
await updateIssue(ctx, issue, results, api)
2828
}
2929
}
30+
process.stdout.write('.')
3031

3132
process.on('unhandledRejection', error => {
3233
console.error('Error', error)

src/issuesToTwoslashRuns.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const issueToTwoslashRun = (ctx: Context) => (issue: Issue): TwoslashRun
2525
const commentCodeBlocks = issue.comments.nodes.map(c => ({
2626
twoslashRuns: markdownToCodeBlocks(c.body).filter(validCodeblocks(ctx.tag)),
2727
commentID: c.id,
28-
description: `<a href='${c.url}'>Comment</a> by @${issue.author.login}</a>`
28+
description: `<a href='${c.url}'>Comment</a> by @${c.author.login}</a>`
2929
}))
3030

3131
// Flatten to Comment -> CodeBlock

src/runTwoslashRuns.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type TwoslashResults = {
2626

2727
export function runTwoslashRuns(issue: Issue, runs: TwoslashRun): TwoslashResults[] {
2828
const oldResults = getPreviousRunInfo(issue)
29-
let latestRuns = runs.codeBlocksToRun.map(runTwoSlash('Nightly'))
29+
let latestRuns = runs.codeBlocksToRun.map(run => runTwoSlash('Nightly')(run))
3030

3131
if (!oldResults) {
3232
// TODO: Fix d.ts for flat
@@ -63,7 +63,7 @@ export const runTwoSlash = (label: string) => (
6363
const typeScripts = ['/home/runner/work/TypeScript/TypeScript/node_modules/typescript']
6464
const t = typeScripts.find(tpath => existsSync(tpath)) || 'typescript'
6565

66-
const tsModule = ts || require(t)
66+
const tsModule = typeof ts === 'object' ? ts : require(t)
6767

6868
try {
6969
const opts = {noErrorValidation: true, noStaticSemanticInfo: true}

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -3836,10 +3836,10 @@ typedarray-to-buffer@^3.1.5:
38363836
dependencies:
38373837
is-typedarray "^1.0.0"
38383838

3839-
typescript@^4.0.0-dev.20200705:
3840-
version "4.0.0-dev.20200705"
3841-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.0-dev.20200705.tgz#4be47176d72af737ae22fec95d74d74773e2c18a"
3842-
integrity sha512-3+B24SpyFO9i43Awv6vgrPC/LcMBtdiPV6i4AH8Td8ZA6EPug1G9svZ5MHKqnIR4kZjarBUtCtQMFjsC55JFIg==
3839+
typescript@^4.2.0-dev.20201207:
3840+
version "4.2.0-dev.20201207"
3841+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.0-dev.20201207.tgz#19a34bc7d2d42a7467c512c63f135587ac848807"
3842+
integrity sha512-fPHBDi/fgdX4WiRC7cFVv/aL069PgUaDWuLYUSHatWZujz/Lkc9bkf/zL3rKdNSCxlNKAMs3fhJv/yompOphZA==
38433843

38443844
union-value@^1.0.0:
38453845
version "1.0.1"

0 commit comments

Comments
 (0)