ahejlsberg Github contribution chart
ahejlsberg Github Stats
ahejlsberg Most Used Languages

Activity

21 Mar 2023

Ahejlsberg

Fix typo

Pushed On 21 Mar 2023 at 08:48:10

Ahejlsberg

Fix recursive type inference (#53396)

Pushed On 21 Mar 2023 at 07:53:18

Ahejlsberg

Fix recursive type inference

Created On 21 Mar 2023 at 07:53:17

Ahejlsberg

Fix subtype reduction involving type variables with union constraints (#53351)

Pushed On 21 Mar 2023 at 07:52:08

Ahejlsberg

Fix subtype reduction involving type variables with union constraints

Created On 21 Mar 2023 at 07:52:07
Issue Comment

Ahejlsberg

Fix subtype reduction involving type variables with union constraints

Fixes #53311.

Forked On 21 Mar 2023 at 07:51:27

Ahejlsberg

Do we need to backport this to 5.0?

I could go either way on that. The underlying issue has been present for years, but the combination of that and an unrelated change in 5.0 caused a regression.

Commented On 21 Mar 2023 at 07:51:27

Ahejlsberg

Exclude comparable relation from literal type relation optimization

Created On 21 Mar 2023 at 07:43:38
Create Branch
Ahejlsberg In microsoft/TypeScript Create Branchfix53400

Ahejlsberg

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

On 21 Mar 2023 at 07:43:05
Issue Comment

Ahejlsberg

Comparability/type assertion failure when using enums and underlying literals

The regression reported here can be traced back to #53192. The minimal~ repro case for it is this:

enum AutomationMode {
  NONE = "",
  TIME = "time",
  SYSTEM = "system",
  LOCATION = "location",
}

interface ThemePreset {
  id: string;
}

interface Automation {
  mode: AutomationMode;
}

interface UserSettings {
  presets: ThemePreset[];
  automation: Automation;
}

interface ExtensionData {
  settings: UserSettings;
}

export function getMockData(): ExtensionData {
  return {
    settings: {
      presets: [],
      automation: {
        mode: "",
      },
    } as UserSettings,
  }
} 

TS playground

Originally posted by @Andarist in https://github.com/microsoft/TypeScript/issues/53192#issuecomment-1476171453

Forked On 21 Mar 2023 at 07:03:40

Ahejlsberg

The fix here is to exclude the comparable relation from the optimization in #53192. I will put up a PR.

Commented On 21 Mar 2023 at 07:03:40
Issue Comment

Ahejlsberg

More complete check in isConstTypeVariable

Fixes #53307.

Forked On 21 Mar 2023 at 02:59:10

Ahejlsberg

Tests and performance all look good.

Commented On 21 Mar 2023 at 02:59:10
Issue Comment

Ahejlsberg

Fix recursive type inference

This PR reverts #49226 and instead fixes the problem as described here.

Fixes #48524. Fixes #52722.

Forked On 21 Mar 2023 at 02:57:03

Ahejlsberg

@typescript-bot perf test faster

Commented On 21 Mar 2023 at 02:57:03
Issue Comment

Ahejlsberg

Fix subtype reduction involving type variables with union constraints

Fixes #53311.

Forked On 21 Mar 2023 at 02:54:38

Ahejlsberg

Tests and performance are unchanged. This one is good to go.

Commented On 21 Mar 2023 at 02:54:38
Issue Comment

Ahejlsberg

Exclude special index signature rule from strict subtype relation

Fixes #53379.

Forked On 21 Mar 2023 at 02:51:52

Ahejlsberg

Tests and performance are unchanged, except for a new error in typeorm. In that code, FindOptionsWhere<any> is resolved to { [x: string]: any }. The error is caused by the fact that any[] is no longer a strict subtype of { [x: string]: any }, so the type in the false branch becomes any[] | FindOptionsWhere<any>, correctly revealing that where might be a zero length array in the false branch. So, new error seems entirely reasonable.

Commented On 21 Mar 2023 at 02:51:52
Issue Comment

Ahejlsberg

Fix recursive type inference

This PR reverts #49226 and instead fixes the problem as described here.

Fixes #48524. Fixes #52722.

Forked On 21 Mar 2023 at 01:11:20

Ahejlsberg

Waiting on the performance suite, everything else looks good.

Commented On 21 Mar 2023 at 01:11:20
Issue Comment

Ahejlsberg

Fix recursive type inference

This PR reverts #49226 and instead fixes the problem as described here.

Fixes #48524. Fixes #52722.

Forked On 20 Mar 2023 at 10:32:59

Ahejlsberg

@MariaSolOs I doubt it, unfortunately.

Commented On 20 Mar 2023 at 10:32:59
Issue Comment

Ahejlsberg

Array.isArray type guard not working in 5.0

Bug Report

🔎 Search Terms

Operator '>' cannot be applied to types

🕗 Version & Regression Information

  • This changed between versions 4.9.5 and 5.0.2

⏯ Playground Link

Playground link with relevant code

💻 Code

declare const a: readonly number[] | number

const isPositive = Array.isArray(a) ? a.every(x => x > 0) : a > 0 

🙁 Actual behavior

Operator '>' cannot be applied to types 'number | readonly number[]' and 'number'. 

🙂 Expected behavior

No error, as Array.isArray(a) is true for arrays

Forked On 20 Mar 2023 at 09:35:24

Ahejlsberg

The thing that changed here is that we more strictly check the > operator. In both 4.9 and 5.0, the type of a in the false branch is readonly number[] | number and not just readonly number[]. The reason for that is that Array.isArray is checks against a non-readonly any[].

Commented On 20 Mar 2023 at 09:35:24

Ahejlsberg

Update test

Pushed On 20 Mar 2023 at 08:14:47

Ahejlsberg

Fix recursive type inference

This PR reverts #49226 and instead fixes the problem as described here.

Fixes #48524. Fixes #52722.

Forked On 20 Mar 2023 at 08:04:24

Ahejlsberg

Yeah. Neat that we already had a test to show the issue.
On 20 Mar 2023 at 08:04:24

Ahejlsberg

Fix recursive type inference

This PR reverts #49226 and instead fixes the problem as described here.

Fixes #48524. Fixes #52722.

Merged On 20 Mar 2023 at 08:04:25

Ahejlsberg

Commented On 20 Mar 2023 at 08:04:25
Issue Comment

Ahejlsberg

Fix recursive type inference

This PR reverts #49226 and instead fixes the problem as described here.

Fixes #48524. Fixes #52722.

Forked On 20 Mar 2023 at 08:01:33

Ahejlsberg

@typescript-bot test this @typescript-bot user test this inline @typescript-bot run dt @typescript-bot perf test faster @typescript-bot test top100

Commented On 20 Mar 2023 at 08:01:33

Ahejlsberg

Fix recursive type inference

Created On 20 Mar 2023 at 08:00:08
Create Branch
Ahejlsberg In microsoft/TypeScript Create BranchfixRecursiveTypeInference

Ahejlsberg

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

On 20 Mar 2023 at 07:57:59
Issue Comment

Ahejlsberg

Fixed issues with inference from nested tuple types of the same shape

fixes #48524 fixes #52722

Forked On 20 Mar 2023 at 07:37:45

Ahejlsberg

I can put up a PR with these changes. Alternatively, @Andarist you can put up a new PR.

Commented On 20 Mar 2023 at 07:37:45
Issue Comment

Ahejlsberg

Fixed issues with inference from nested tuple types of the same shape

fixes #48524 fixes #52722

Forked On 20 Mar 2023 at 07:35:48

Ahejlsberg

I have a fix for this. We solved a similar problem in isDeeplyNestedType by tracking whether type IDs are increasing as we move up the recursion tracking stack. Increasing type IDs indicate newly generated types, and those we want to count, whereas decreasing type IDs indicate manually written instantiations that we don't want to count. However, the circularity checking in invokeOnce doesn't use isDeeplyNestedType, so it doesn't benefit from this. But with this change it can:

 function invokeOnce<Source extends Type, Target extends Type>(source: Source, target: Target, action: (source: Source, target: Target) => void) {
            const key = source.id + "," + target.id;
            const status = visited && visited.get(key);
            if (status !== undefined) {
                inferencePriority = Math.min(inferencePriority, status);
                return;
            }
            (visited || (visited = new Map<string, number>())).set(key, InferencePriority.Circularity);
            const saveInferencePriority = inferencePriority;
            inferencePriority = InferencePriority.MaxValue;
            // We stop inferring and report a circularity if we encounter duplicate recursion identities on both
            // the source side and the target side.
            const saveExpandingFlags = expandingFlags;
            (sourceStack ??= []).push(source);
            (targetStack ??= []).push(target);
            if (isDeeplyNestedType(source, sourceStack, sourceStack.length, 2)) expandingFlags |= ExpandingFlags.Source;
            if (isDeeplyNestedType(target, targetStack, targetStack.length, 2)) expandingFlags |= ExpandingFlags.Target;
            if (expandingFlags !== ExpandingFlags.Both) {
                action(source, target);
            }
            else {
                inferencePriority = InferencePriority.Circularity;
            }
            targetStack.pop();
            sourceStack.pop();
            expandingFlags = saveExpandingFlags;
            visited.set(key, inferencePriority);
            inferencePriority = Math.min(inferencePriority, saveInferencePriority);
        } 

Plus change the declarations of sourceStack and targetStack to have type Type[].

Best I can tell this takes care of the problem.

Commented On 20 Mar 2023 at 07:35:48
Issue Comment

Ahejlsberg

Fixed issues with inference from nested tuple types of the same shape

fixes #48524 fixes #52722

Forked On 20 Mar 2023 at 06:57:36

Ahejlsberg

Just noticed this was merged, but it causes an issue in this example:

type T1<T> = [number, T1<{ x: T }>];
type T2<T> = [42, T2<{ x: T }>];

function qq<U>(x: T1<U>, y: T2<U>) {
    x = y;  // Excessive stack depth comparing types 'T2<U>' and 'T1<U>'
    y = x;  // Error as expected
} 

The change in the PR effectively disables isDeeplyNestedType checks for tuples and we end up hitting the excessive stack depth panic backstop.

Commented On 20 Mar 2023 at 06:57:36
Issue Comment

Ahejlsberg

Exclude special index signature rule from strict subtype relation

Fixes #53379.

Forked On 20 Mar 2023 at 06:17:13

Ahejlsberg

@typescript-bot test this @typescript-bot user test this inline @typescript-bot run dt @typescript-bot perf test faster @typescript-bot test top100

Commented On 20 Mar 2023 at 06:17:13

Ahejlsberg

Exclude special index signature rule from strict subtype relation

Created On 20 Mar 2023 at 06:16:34