Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 04:19
    sheetalkamat synchronize #50007
  • 04:19

    sheetalkamat on cacheModuleResolution

    Dont store originalPath as sepa… (compare)

  • 04:16
    sheetalkamat synchronize #50007
  • 04:16

    sheetalkamat on cacheModuleResolution

    Always respect preserveSymlinks Dont store originalPath as sepa… (compare)

  • 03:35
    sheetalkamat synchronize #50007
  • 03:35

    sheetalkamat on cacheModuleResolution

    Store resolvedFileName as fileI… (compare)

  • 03:25
    sheetalkamat synchronize #51842
  • 03:25

    sheetalkamat on alwaysSymlink

    Accept baselines (compare)

  • 02:01
    github-actions[bot] synchronize #51842
  • 02:01

    github-actions[bot] on alwaysSymlink

    Update Baselines and/or Applied… (compare)

  • 01:47
    sheetalkamat synchronize #50007
  • 01:47

    sheetalkamat on cacheModuleResolution

    Store resolvedFileName as fileI… (compare)

  • 01:24
    DanielRosenwasser edited #51843
  • 01:24
    DanielRosenwasser labeled #51843
  • 01:24
    DanielRosenwasser opened #51843
  • 01:11
    DanielRosenwasser assigned #51829
  • 01:11
    DanielRosenwasser milestoned #51829
  • 00:53
    RyanCavanaugh labeled #51841
  • 00:53
    RyanCavanaugh labeled #51841
  • 00:53
    sheetalkamat synchronize #51842
0xAFFE
@tim:schumacher.im
[m]
I once played with https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph and it went pretty well
[pihentagy]
@pihentagy:matrix.org
[m]
Typescript itself has tools to manipulate ast. It's in the official docs (by MS)
hinell
@hinell
BruceGitHub
@BruceGitHub
Hi guys
it's possible to instruct typescript / vscode to read the definition type for one file?
hello.js > hello.d.ts
this works for the file that uses the function inside a hello.js but doesn't work for hello.js itself
...
In my case only a compile-time to have a check types but not in the build, because this file currently is run with node without ts (the hello.js)
BruceGitHub
@BruceGitHub
BruceGitHub
@BruceGitHub
but this approach creates duplicate definitions :-(
BruceGitHub
@BruceGitHub
Bruce Pascoe
@fatcerberus
no, .d.ts isn't a header file
it's only for consumers of your code
Jacob Madsen
@jacobmadsen
Anyone know how to use TSDoc to describe a function param where the param's type is a union of string literals. Something like isnt working:
/**
 * Where Query
 *
 * @param key name
 * @param {'='} operator equal
 * @param {'!='} operator not equal
 * @param param parameter
 */
function where(key: string, operator: '=' | '!=', param: unknown): void {}
hinell
@hinell
I've created an issue in #vscode repo to dissucss whether we should have a separate language support for #zsh scripts or not. Please checkout:
microsoft/vscode#164985
tmerse
@tmerse:matrix.org
[m]
Can anyone tell me, what I need to do in order for this to be typed properly?
property test of interface FM should be an array consisting of two values: first the key of property of SomeInterface. The second value inside the array should be the respective value.
Erol
@FrEaKmAn

hi all.. if I have following function,

function foo() {

}

foo.extra = function() {}

how can I define typings for this?

2 replies
Jacob Bogers
@Jacob_Bogers_twitter
Hi
I am having a problem with typescript paths, i do things like `import { something } from '@path123/file' how can i make it that it appens a ".js" at the end (I want to using esm modules)
1 reply
Bruce Pascoe
@fatcerberus
not to be confused with https://flow.org/ I assume
Nikola Pavlovic
@raegen

so, I'm having a very amusing case:
TS 4.6.4

Type 'T | undefined' is not assignable to type 'T | T[] | undefined'

Nikola Pavlovic
@raegen
is this expected behaviour? How come?
Tom Enden
@tomenden
I'm having trouble extracting Parameters Union from a generic function. Seems like Parameters is not behaving as I expected it to, Playground - https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzDigxABEQA3AUWCwxxgGEIsRUMAKASgC54BvAFDwR8PHyGip8DpTYY+AcloBnMHlTgSwRQBoCUCBABGUMAGs+3eAF4AfPAo4swXo+fAA3MOkjZFeSU4dVRNTBAdfTBDEzNLGS5bBycXNxSvHxEAX28cwUEMAE8ABwRyalp6JhZ5W3gAJRAMZBhUABUSkAAeItKcRAIiEnKaOgZmVnY7As74AHlUADE0TFx8G3gRyvGa9gBtRTxFAF18mdL4KgD2ADkoAFsQFTqABVgHppAYFS6F5fRsHg7HsAAynAD04PgoBUWDgwHgAFp4CAAB4YGBmDDwGLwYo4FSw4wQBByW4fFRKVQhMLaRTwAA+8EUwQ0WgiikEkJxmGQhiRl2uGDuj2eWGeeAghXgGAAFghoCpsXgEMiWeA2eEdPkgA
declare function createDevEditorClient(): {
    on: {
        (event: 'disconnected', callback: () => void): void;
        (event: 'reconnected', callback: () => void): void;
    };
};

type DevEditorClient = ReturnType<typeof createDevEditorClient>
type OnFunction = DevEditorClient['on']


type EventNames = Parameters<OnFunction>[0]
// desired - extract all possible eventNames: 'disconnected' | 'reconnected'
// actual - EventNames is only the last one - 'reconnected'
5 replies
cphoover
@cphoover

Does anyone have experience using node.js stream package with typescript?

Seems like typescript support is lacking ... e.g. Readable/Writeable from node.js do not have generics as part of their declaration for objectMode streams of a certain type...

Also... the compose function is not found in typescript

When I try and import { compose } from 'stream' I get

'Module stream has no exported member compose

Salathiel Genese
@SalathielGenese

Hi everyone,

Please I have typing issues for the last couple of lines.
(At first, I thought my IDE was trying to me smart, but I just reproduced it on TypeScript official playground)

The question is how to fix?

type Capture<T> = string | symbol & Record<never, T>;
type Target<C> = C extends Capture<infer T> ? T : never;
declare function resolve<C extends Capture<any>>(key: C): Target<C>;
declare function resolve(key: string): unknown;
declare function resolve(key: number): never;

let valueTypeNever = resolve(0); // never: OK
let valueTypeUnknown = resolve(''); // unknown: OK
let shouldBeValueTypeNumber = resolve('' as Capture<number>); // unknown: KO
let shouldBeValueTypeString = resolve(Symbol('') as Capture<string>); // unknown: KO
[pihentagy]
@pihentagy:matrix.org
[m]
Not clear to me what resolve tries to achieve.
Wild guess: try specifying the type parameter by hand. as is evil.
resolve<MyType>(whatever) instead of resolve(whatever as SomeType)
Btw seems you are trying some type juggling. Have you heard about zod?
Salathiel Genese
@SalathielGenese

Not clear to me what resolve tries to achieve.

The implementation? IoC

IoC/DI type inference, to be accurate.

Salathiel Genese
@SalathielGenese
Christopher Thomas
@christhomas
Is there any way to define interfaces for my entire app without having to import everything manually all the time?
Salathiel Genese
@SalathielGenese

:point_up: December 4, 2022 3:31 PM

tsconfig.json compilerOptions.types will auto-import typings.

[pihentagy]
@pihentagy:matrix.org
[m]
Because list needs the property c.
Maybe you meant property z in line 4.
BruceGitHub
@BruceGitHub
But 'c' is in the computes property
[foo.hello] // 'c'
Bruce Pascoe
@fatcerberus
the compiler doesn't know that. it just sees a computed property that's a string
it works if you declare const foo = {hello: "c"} as const;
then it knows [foo.hello]: resolves to property c
BruceGitHub
@BruceGitHub
ah ok
so the problem is the computed properties ?
bemon
@bemon

Hi, i have problem with generic type extraction, lets say we have class Model, class QueryScope and class SelectQueryBuilder, I want to extend return type of static method in Model class to return SelectQueryBuilder & Scope, code below:

abstract class Scope {   }
abstract class SelectQueryBuilder<M extends Model<any>>{
  public query() { return "bar";}
}

abstract class Model<S extends Scope> { 

  public static where<T extends typeof Model>(this: T) : SelectQueryBuilder<InstanceType<T>> & S {}

}

class UserScope extends Scope { 
  public NonBannedUsers(this : SelectQueryBuilder<User>) { 
    return 'bla bla'
  }
}

class User extends Model<UserScope>{ 

}

User.where().NonBannedUsers();

and i know that i cannot use class generic type in static method, but this shows the idea. I tried numerous times to implement something similar and i stuck with it.

BruceGitHub
@BruceGitHub

I read this
https://bobbyhadz.com/blog/typescript-reduce-type
I have the same situation
but as return type, I should get the
initial type - return type
so
initial type = a,b,c,d,e,f,g
return type = a,b,c,d

inside the accumulator function, I put a type guard to skip e,f,g but the acc type is a,b,c,d,e,f,g so with or without the typeguard for ts all it's ok
... some suggestion ?

Salathiel Genese
@SalathielGenese

:point_up: December 7, 2022 4:23 PM
:point_up: December 7, 2022 5:39 PM

Please, minimal reproducible example at https://www.typescriptlang.org/play ?

I wonder for instance what QueryScope definition is. It is easier if/when we see it.

bemon
@bemon
@SalathielGenese i want to return merged types of queryscope and querybuilder, definition is irrelevant, it can be anything, mostly functions that modifies original query. i want to do it like this for simplicity & code readability
i just want to extract class generic type in static function
Salathiel Genese
@SalathielGenese
:point_up: December 8, 2022 9:04 AM
Then you are doing it right.
bemon
@bemon
if anybody wonders how i resolve this here is sample code sample