profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/basarat/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.
Basarat Ali Syed basarat http://designtsx.com Melbourne, Australia http://youtube.com/basaratali That #TypeScript guy. If you like my work please click the follow button 🌹

alm-tools/alm 2872

:rose: A :cloud: ready IDE just for TypeScript :heart:

basarat/algorithms 233

🌹 Code / tests for algorithm and data structure lessons using TypeScript / JavaScript

basarat/algorithms-book 30

The book a CS student can use to refresh their knowledge of Data Structures and Algorithms or just review how to do them in TypeScript

basarat/alertOnLeave 6

add an alert on leave check :rose: :heart:

basarat/angular-for-react-devs 2

You know react? Great. Lets see how concepts map to angular 🌹

basarat/asyncawait 1

Callback heaven for Node.js with async/await

startedant-design/ant-design

started time in 32 minutes

startedant-design/ant-design

started time in 38 minutes

startedant-design/ant-design

started time in 42 minutes

startedant-design/ant-design

started time in an hour

startedant-design/ant-design

started time in an hour

startedant-design/ant-design

started time in an hour

issue commentmicrosoft/TypeScript

Omitting "dom" from lib should enforce excluding lib.dom.d.ts (for nodejs)

This can be also very annoying when you have some types with identical names available in your global scope.

In my project, I have a global class Location declared. Pulling in a dependency that enables dom lib breaks compilation.

bluenote10

comment created time in an hour

issue commentmicrosoft/TypeScript

Provide a quick-fix for non-exported types

I assume nobody is working on this at the moment? If so, I would like to take a shot @DanielRosenwasser

DanielRosenwasser

comment created time in 2 hours

issue commentmicrosoft/TypeScript

Alias type for indexing a generic object with with transform breaking change in 4.2+ (2nd issue)

@RyanCavanaugh made the issue in OP more specific and fleshed out the types a bit more. Felt like it was different enough to open a new one: #44108

iPherian

comment created time in 4 hours

issue openedmicrosoft/TypeScript

Indexing a type which was made via intersections produces an intersection of it's value types instead of a union

Bug Report

<!-- Please fill in each section completely. Thank you! -->

🔎 Search Terms

<!-- What search terms did you use when trying to find an existing bug report? List them here so people in the future can find this one more easily. --> indexing intersections, generic object indexing

🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed. For npm: typescript@next This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies: -->

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about indexing intersections, etc

⏯ Playground Link

<!-- A link to a TypeScript Playground "Share" link which shows this behavior

The TypeScript Workbench can be used for more complex setups, try https://www.typescriptlang.org/dev/bug-workbench/

As a last resort, you can link to a repo, but these will be slower for us to investigate. --> Playground link with relevant code

💻 Code

<!-- Please post the relevant code sample here as well-->

type PropsNotShared<LHS extends {}, RHS extends {}> = Omit<RHS, keyof LHS> &
  Omit<LHS, keyof RHS>;

export function handlePropsNotShared<LHS extends {}, RHS extends {}>(
  lhs: LHS,
  rhs: RHS
) {
  /**
   * [====================================]
   * Set everything up first:
   * [====================================]
   */

  /**
   * Assertion because it's just for checking types.
   */
  const notShared = {} as PropsNotShared<LHS, RHS>;
  /**
   * ts says the type of keyofNotShared is:
   *
   *   ```Exclude<keyof RHS, keyof LHS> | Exclude<keyof LHS, keyof RHS>```
   *
   * Which makes sense, given @see PropsNotShared
   */
  const keyofNotShared = {} as keyof typeof notShared;
  const keyofNotShared_firstSet = {} as Exclude<keyof RHS, keyof LHS>;
  const keyofNotShared_secondSet = {} as Exclude<keyof LHS, keyof RHS>;
  /**
   * Check that the above two types are indeed keys of notShared. Succeeds
   * because they are.
   */
  const checkKeyofNotShared_firstSet: keyof typeof notShared =
    {} as typeof keyofNotShared_firstSet;
  const checkKeyofNotShared_secondSet: keyof typeof notShared =
    {} as typeof keyofNotShared_secondSet;
  /**
   * Expected failures to illustrate that `keyofNotShared_firstSet` and
   * `keyofNotShared_secondSet` are not identical (not assignable to each
   * other).
   */
  const checkKeySetsNotSame_1: typeof keyofNotShared_firstSet =
    {} as typeof keyofNotShared_secondSet;
  const checkKeySetsNotSame_2: typeof keyofNotShared_secondSet =
    {} as typeof keyofNotShared_firstSet;
  /**
   * Some sets of values from notShared.
   */
  const notSharedVals_firstSet =
    {} as typeof notShared[typeof keyofNotShared_firstSet];
  const notSharedVals_secondSet =
    {} as typeof notShared[typeof keyofNotShared_secondSet];
  /**
   * Expected failures to show that `notSharedVals_firstSet` and
   * `notSharedVals_secondSet` are not identical.
   */
  const checkValSetsNotSame_1: typeof notSharedVals_firstSet =
    {} as typeof notSharedVals_secondSet;
  const checkValSetsNotSame_2: typeof notSharedVals_secondSet =
    {} as typeof notSharedVals_firstSet;

  /**
   * [====================================]
   * And now the main problems:
   * [====================================]
   */

  /**
   * (1)
   *
   * Should succeed but doesn't.
   *
   * Shouldn't a union of some values from notShared (rhs) be assignable to:
   * `typeof notShared[keyof typeof notShared]` (lhs) ?
   */
  const x1: typeof notShared[keyof typeof notShared] = {} as
    | typeof notSharedVals_firstSet
    | typeof notSharedVals_secondSet;
  /**
   * (2)
   *
   * (This is the issue referenced in title):
   *
   * Should fail, I would think.
   *
   * How is an interection of some of the values from an object (rhs)
   * assignable to a type which is any value of that object (lhs) ?
   *
   * (when the types of those values are not identical,
   * And they aren't according to above lines involving
   * `checkValSetsNotSame_1` and `checkValSetsNotSame_1`.)
   */
  const x2: typeof notShared[keyof typeof notShared] =
    {} as typeof notSharedVals_firstSet & typeof notSharedVals_secondSet;
  /**
   * (3)
   *
   * More weirdness:
   *
   * Should fail but doesn't.
   *
   * I would think, as doesn't it basically say A | B == A & B ?
   * (and A and B aren't identical)
   */
  const x3: typeof notSharedVals_firstSet | typeof notSharedVals_secondSet =
    {} as typeof notSharedVals_firstSet & typeof notSharedVals_secondSet;
}

🙁 Actual behavior

Given a generic object produced via an intersection, a union of it's values is not assignable to Obj[keyof Obj] (i.e. any value of it) (example 1 in comments), but an intersection is and shouldn't be (example 2 and in title).

🙂 Expected behavior

Assigning a union of it's values to Obj[keyof Obj] should succeed (example 1) and assigning an intersection of them should (I suppose) fail (example 2).

created time in 4 hours

issue closedmicrosoft/TypeScript

Conditionally inferred class type loses private properties

Bug Report

Conditional infer of a class type is not the class type but only the public interface of it.

🔎 Search Terms

infer, inferred, conditional, private, class

🕗 Version & Regression Information

4.2.3

⏯ Playground Link

Playground link with relevant code

💻 Code

type AllStrings<T> = { [key in keyof T]: string; };
type Container<T> = T extends AllStrings<infer BaseT> ? { strings: T; base: BaseT; } : never;

class AClass {
  public doSomething(aValue: string): string {
    return this._doItPrivately(aValue);
  }

  private _doItPrivately(aValue: string): string {
    return `${aValue}_done`;
  }
}

class AClassStrings implements AllStrings<AClass> {
    public doSomething: string = 'done';
}

// Error with `Property '_doItPrivately' is missing in type '{ doSomething: unknown; }' but required in type 'AClass'`
// The type is inferred and should be AClass
const returnAClassBase = (container: Container<AClassStrings>): AClass => container.base;

🙁 Actual behavior

Errors with Property '_doItPrivately' is missing in type '{ doSomething: unknown; }' but required in type 'AClass

🙂 Expected behavior

Should infer the class type correctly and not give error

closed time in 4 hours

Pmyl

issue commentmicrosoft/TypeScript

Conditionally inferred class type loses private properties

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Pmyl

comment created time in 4 hours

PR opened microsoft/TypeScript

fix(41299): Support Intl.NumberFormat.formatToParts in ES2018

<!-- Thank you for submitting a pull request!

Please verify that:

  • [x] There is an associated issue in the Backlog milestone (required)
  • [x] Code is up-to-date with the master branch
  • [x] You've successfully run gulp runtests locally
  • [x] There are new or updated unit tests validating the change

Refer to CONTRIBUTING.MD for more details. https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md -->

Fixes #41299

+74 -80

0 comment

9 changed files

pr created time in 5 hours

issue commentmicrosoft/TypeScript

Tooltips / IntelliSense: Don't resolve type aliases (aka "semantic sugar") set explicitly

@miyauchiakira True, just adding & {} (which does not change the type at all) causes TypeScript not to expand the type. I have no idea why this workaround works. Ugly, but effective – still would prefer TypeScript to "just work".

Sgt-Nukem

comment created time in 5 hours

startederroneousboat/slack-term

started time in 6 hours

issue commentmicrosoft/TypeScript

TS intellisense getting tripped on const object indexes

Would it convert to 'foo' if a is not in current scope?

qwelias

comment created time in 6 hours

issue commentmicrosoft/TypeScript

Expression produces a union type that is too complex to represent

I should note: It's only when I introduced WithStringProperty that I started having problems. My entire Redux store is wrapped in a Deepreadonly and it's never had problems before.

MichaelTontchev

comment created time in 7 hours

issue commentmicrosoft/TypeScript

Expression produces a union type that is too complex to represent

@RyanCavanaugh Yeah, the above is a minimal repro of the issue. In reality, the DeepReadonly wraps a slice of my Redux state, and the function above is actually part of a cache utility class that takes in the cache in my redux slice and wraps it so that it can easily be queried and written to. The reason I take in a field name is because the cache clients may pass in different structures they want cached, and parameterizing the field name allows them to handle the different cases. So, roughly, I have a state slice that looks like Map<ItemId, { itemMetadata: ICached<IMetadata>; // other stuff... }> And I want the cache utility class to take in an ID of an Item to retrieve/cache, access the map above, and then chache the metadata part inside. The "other stuff needs no caching". Other clients of the cache class may have a similar two-level structure, but their field name won't be "itemMetadata", it may be "elementMetadata" (you may notice these are just placeholders :P )

MichaelTontchev

comment created time in 7 hours

issue commentmicrosoft/TypeScript

Typescript unable to infer property type with utility type's index signature

Just realized the angle brackets disappeared. Does that mean I can inject HTML? That's interesting.

Here's the playground link: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgPICMBWyDeBYAKGWRgHtSAuZEAVwFt1pDj04oraGmjlWAvDvUZRCAX0JgAngAcUAZRrpkAXjR1gYADwZMAGmQAifgYB8hQgBsIYZKSxUdK3GUrIAjPtbt3nuAPfiBIQwNCAIYMCkICTRmgDSyBAAHpAgACYAzsgA1hCSpDDICugmABS5klRx+gBucBZUxQDacQC6AJS4zLZYTRWtTnUWYkA

Kaseano

comment created time in 7 hours

issue commentmicrosoft/TypeScript

TS intellisense getting tripped on const object indexes

https://user-images.githubusercontent.com/6630042/118371160-d91eb400-b5dd-11eb-8324-1a877318a1ba.mp4

Currently, only the first identifier Symbol is displayed on the completion list. It would be more intuitive if the whole expression Symbol.iterator is provided.

qwelias

comment created time in 8 hours

issue commentmicrosoft/TypeScript

What do you not like about DefinitelyTyped as a user and contributor?

npm run test-all could be highlighted and better documented

test-all checks the packages I changed as well as the packages that depend on them. That's great! It's exactly what I want. I get confidence that my changes are correct without having to wait for the tools to check thousands of unrelated packages. But it's only mentioned in passing in the README, it's not part of the steps for preparing a PR, and I haven't found any documentation that explains that what you have to do to make it work correctly. (IIRC: have your fork's master branch and the current branch up to date with the main repo, and check everything in.) I bet more PRs would land cleanly the first time if this were better documented and recommended as part of the process for preparing a PR.

Tags: documentation

orta

comment created time in 8 hours

issue commentmicrosoft/TypeScript

ConditionalRoot.isDistributive is buggy

@RyanCavanaugh Sorry, I had one more thought. Using the resolved type to determine whether or not a conditional is distributive means that some conditionals will be distributive with some compiler options, but not with others. eg type MaybeDistributive<T, U> = T|null extends U|null ? T : never; is distributive unless compiled with strictNullChecks (btw, I tried to set this up in the playground, but I found that although I can specify the tsconfig, I couldn't make the playground actually use it; no matter what I did, strictNullChecks was off - even though the checkbox is ticked by default).

This definitely seems wrong to me... I mean, obviously, strictNullChecks is supposed to change the behavior of the program, but this is a pretty unexpected change.

I also found, (rather surprisingly to me) that (T[])[number] is always considered to be a naked type parameter, regardless of strictNullChecks or noUncheckedIndexedAccess. That seems like a bug (independent of distributive conditionals). eg

function g(x : (T[])[number]) { return x; }
g(undefined);

Should accept the call to g, since x should be of type number|undefined (or am I missing something here)? There's a similar issue with Record<string,T>["foo"]. And of course, I was looking at this kind of expression because I expected it to be another expression whose nakedness depended on compile time options...

markw65

comment created time in 9 hours

issue openedmicrosoft/TypeScript

Cannot read property 'length' of undefined

Imported from microsoft/tsserverfuzzer#314

Repo Name: https://github.com/yarnpkg/yarn.git

Revision: 3119382885ea373d3c13d6a846de743eca8c914b

TypeScript Version: 4.3.0-dev.20210410

Commands:

{"response":[],"responseRequired":true}
{"command":"format","arguments":{"endLine":3,"endOffset":1,"line":3,"offset":1,"file":"D:/local/Temp/fuzzerWorkingDir/yarn/src/util/normalize-manifest/licenses.js","options":{}},"type":"request","seq":26}
{"response":[],"responseRequired":true}
{"command":"getCodeFixes","arguments":{"errorCodes":[1],"startLine":3,"startOffset":1,"endLine":3,"endOffset":1,"file":"D:/local/Temp/fuzzerWorkingDir/yarn/src/util/normalize-manifest/licenses.js"},"type":"request","seq":27}
{"response":[],"responseRequired":true}
{"command":"getApplicableRefactors","arguments":{"startLine":3,"startOffset":1,"endLine":3,"endOffset":1,"file":"D:/local/Temp/fuzzerWorkingDir/yarn/src/util/normalize-manifest/licenses.js"},"type":"request","seq":27}
{"response":[{"name":"Convert export","description":"Convert default export to named export","actions":[{"name":"Convert default export to named export","description":"Convert default export to named export","kind":"refactor.rewrite.export.named"}]}],"responseRequired":true}
{"command":"getApplicableRefactors","arguments":{"startPosition":30,"endPosition":31,"file":"D:/local/Temp/fuzzerWorkingDir/yarn/src/util/normalize-manifest/licenses.js"},"type":"request","seq":28}
{"response":[{"name":"Convert export","description":"Convert default export to named export","actions":[{"name":"Convert default export to named export","description":"Convert default export to named export","kind":"refactor.rewrite.export.named"}]}],"responseRequired":true}
{"command":"getEditsForRefactor-full","arguments":{"refactor":"Convert export","action":"Convert default export to named export","startPosition":30,"endPosition":31,"file":"D:/local/Temp/fuzzerWorkingDir/yarn/src/util/normalize-manifest/licenses.js"},"type":"request","seq":29}
(Showing last 10 of 96829 commands)

Code (src\util\normalize-manifest\licenses.js):

  /* @flow */
  
  /* eslint-disable max-len */
//                 ^
  
  /**

Hash: 118a1b4b6ad0276ad98f166743ace4f4 Stack trace:

Cannot read property 'length' of undefined
    at escapeLeadingUnderscores (tsserverlibrary.js:12173:28)
    at createBaseIdentifier (tsserverlibrary.js:21609:35)
    at createIdentifier (tsserverlibrary.js:21621:24)
    at makeExportSpecifier (tsserverlibrary.js:148021:143)
    at changeExport (tsserverlibrary.js:147894:32)
    at doChange (tsserverlibrary.js:147886:13)
    at <anonymous> (tsserverlibrary.js:147833:94)
    at ChangeTracker.with (tsserverlibrary.js:138743:17)
    at getEditsForAction (tsserverlibrary.js:147833:62)
    at getEditsForRefactor (tsserverlibrary.js:139972:41)

created time in 9 hours

startedbasarat/typescript-script

started time in 10 hours

issue commentmicrosoft/TypeScript

TS intellisense getting tripped on const object indexes

Did you try a? It will convert c. to c[a] and let you change it to c[a.foo] which is how it's declared in c.

qwelias

comment created time in 11 hours

startedbasarat/typescript-book

started time in 12 hours

issue commentmicrosoft/TypeScript

Generate TypeScript files by combining TypeScript declaration files and corresponding JavaScript files

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

ApsarasX

comment created time in 12 hours

issue commentmicrosoft/TypeScript

Template string literal highlighting breaks on ternary operator with typeof

This seems to be fixed in VSCode Insiders. Specifically, using VSCode 1.56.0-insider.

image

image

vinnikov

comment created time in 12 hours