Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 17:57
    a-tarasyuk synchronize #46416
  • 17:53
    typescript-bot synchronize #43554
  • 17:53
    typescript-bot labeled #46431
  • 17:53
    typescript-bot synchronize #43554
  • 17:53
    a-tarasyuk opened #46431
  • 17:53
    typescript-bot synchronize #43554
  • 17:29
    sandersn closed #44927
  • 17:23
    DanielRosenwasser closed #46426
  • 17:23
    DanielRosenwasser labeled #46426
  • 17:13

    csigs on hb_5378966c-b857-470a-8675-daebef4a6da1_20211019171250176

    (compare)

  • 17:13

    csigs on main

    LEGO: Merge pull request 46430 … (compare)

  • 17:13
    csigs closed #46430
  • 17:13
    typescript-bot labeled #46430
  • 17:13
    csigs opened #46430
  • 17:13

    csigs on hb_5378966c-b857-470a-8675-daebef4a6da1_20211019171250176

    LEGO: check in for main to temp… (compare)

  • 16:58

    ahejlsberg on main

    Improve logic for choosing betw… (compare)

  • 16:58

    ahejlsberg on fix45603

    (compare)

  • 16:58
    ahejlsberg closed #46392
  • 16:58
    ahejlsberg closed #45603
  • 16:48
    ahejlsberg review_requested #46429
Keith Layne
@keithlayne
My project won't build without it.
I think it's not terrible to enable for apps
YMMV
papaiatis
@papaiatis
thanks for looking into it though!
just got a feedback from octokit and they confirmed they require TS v4+ for this to work.
at least I have a plan B to workaround this problem
Archimedes Trajano
@trajano

Can I rewrite this so that I don't have the const?

const theme: ITheme = { color: 'blue' }
export default theme;

I tried

export default : ITheme : {color: Blue}

and the following will disable type checks

export default  {color: Blue} as ITheme
1 reply
Tõnis Ostrat
@tonisostrat

heya. i'm working on a React project and i'm having trouble with typings.

let's say that i have the following component

export const FancyComponent = withFoo(withBar(withFizz((props) => {
  const { foo, bar, fizz } = props;

  // render logic
})));

the HoC-provided prop types are automatically inferred but where (and how) should i define my own props? i want to, for example, pass a msg: string type in

N.S. Cutler
@godenji
export enum RosterPosition {
  LW = 'Left Wing',
  RW = 'Right Wing',
  C = 'Center',
  LD = 'Left Defense',
  RD = 'Right Defense',
  G = 'Goalie'
}

export namespace RosterPosition {
  export const all = new Map<string, RosterPosition>()
  Object.keys(RosterPosition).forEach(x => {
    console.log(x)
    all.set(x, RosterPosition[x])
  })
}

[LOG]: "LW" 
[LOG]: "RW" 
[LOG]: "C" 
[LOG]: "LD" 
[LOG]: "RD" 
[LOG]: "G" 
[LOG]: "all" // tf is this doing here??
N.S. Cutler
@godenji
Filed an issue on this and was clued into the cause -- RosterPosition.all is exported and therefore merged into the Enum. Very puzzling behavior but now I see what's happening.
Jacob Madsen
@jacobmadsen
Is it possible to define a method-decorator where the decorator can set a class method's arguments-type on the method in question? Naive example:
function methodDecorator<V>(v: V) {
  return <Name extends string>(
    target: { [N in Name]: (v: V) => any },
    propertyKey: Name,
    descriptor: PropertyDescriptor
  ) => {}
}

class A {
  @methodDecorator(1)
  someMethod(v) {} // Parameter 'v' implicitly has an 'any' type
}
Salathiel Genèse
@SalathielGenese
Yes, it is possible
Salathiel Genèse
@SalathielGenese
function Default<T>(defaultValue: T) {
    return function <O>(target: O, method: MethodWithParameter<O, T, 0>) {
        //
    }
}

type MethodWithParameter<T, PT, I extends number = number, K extends keyof T = keyof T> =
    K extends any ? T[K] extends (...args: any[]) => any ?
    Parameters<T[K]>[I] extends PT ? K : never
    : never : never;
The complete example, with variants, on TypeScript playground
@jacobmadsen
Danilo Silva
@danilosilvadev

Hello guys i have a question about NPM. I created a script to copy files into a dist folder. I'm doing a local private NPM library using verdaccio. But it just copy paste the files without transpile the typescript into JS. Can someone help me with what is missing?

"distribute": "set NODE_ENV=production&&babel src --out-dir dist --copy-files --ignore spec.js,test.js --source-maps"

webstrand
@webstrand
set NODE_ENV=production&&babel doesn't look valid, unless you're using some other shell?
2 replies
if you're using bash or dash then NODE_ENV=production babel is what you want
no idea about getting babel to transpile, though.
Jacob Madsen
@jacobmadsen
@SalathielGenese Thanks. What I am looking for is a way to get the parameter type from the decorator so it is not implicit any
Salathiel Genèse
@SalathielGenese
@jacobmadsen - I tried that couple of years ago and failed. Because...
TypeScript (or rather the old decorator spec) resolve the decorator options before applying the decorator implementation
And not the other way around
If we move <O> to the decorator option level, and use it *as one of the decorator's options, that fine (because TypeScript can capture O type right there)
Otherwise, it is inferred to object pass that point and is object by the time the decorator implementation (as opp. to its option-function) get evaluated.
Salathiel Genèse
@SalathielGenese

[UPDATE]

There technical idoms to better describe it, but I don't know them.

Jacob Madsen
@jacobmadsen
@SalathielGenese Ok, it seems to be impossible as of now. Thank you
Salathiel Genèse
@SalathielGenese
yw
Gregor
@Gregoor
Any MappedType wizards here? I'm wondering if I could get rid of the as anys in this playground
4 replies
Salathiel Genèse
@SalathielGenese
@Gregoor , what you're doing there iss beautiful
Salathiel Genèse
@SalathielGenese
import { mapValues } from "lodash";

type LabeledRoutes = Record<string, string | readonly [string, readonly string[]]>;
type ActionedRoute<R extends LabeledRoutes[keyof LabeledRoutes]> = R extends string ? string : (params: Record<R[1][0], string>) => string;

const parameterizeRoutes = <R extends LabeledRoutes>(routes: R): { [RK in keyof R]: ActionedRoute<R[RK]> } =>
  mapValues(routes, (route) => {
  // ... removed for brevity
Andreas Herd
@mendrik
anyone one up for a TS challenge to solve this SO question:
https://stackoverflow.com/questions/69583908/type-guarding-the-2nd-argument-of-a-curried-function I've been banging my head for days now
Jacques Yakoub
@jy95

Hello, I created a CLI tool (https://github.com/jy95/i18n-tools) and I want my code to be also consumable as an actual module so that others can reuse my logic in their code for example creating a GUI. Which build tool (rollup, parceljs, ...) could fit that need as simpler as possible ?

Thanks in advance

Keith Layne
@keithlayne
You don't need a build tool for that - you can just publish an npm that has an executable for your CLI, and the programmatic API in the library.
Masood Ahmad
@sircle:matrix.org
[m]
Hi, can anyone advise on ...spread and things in these highlighted lines? https://pastebin.mozilla.org/vr6ynGxv#L33,52
Masood Ahmad
@sircle:matrix.org
[m]
What harm would I get by using it
using spread in this case
Keith Layne
@keithlayne
Pro Tip™: use the playground, and make your examples not horribly broken, if you want help. Your case probably doesn't really need it, but all that stuff in a pastebin is distracting.
Keith Layne
@keithlayne
Here's your example in playground @sircle:matrix.org
Your stuff is so broken that even though you're just asking for generalities it's hard to see how the embedded questions really relate to your example.
Keith Layne
@keithlayne
  1. You always have to type props, pretty much. You can use any as a fallback.
  2. If libs don't have types, you can start with declare module 'whatever-lib'; and go from there. I'd personally avoid libs without types. If they're complex and don't have types, you're looking at a ton of work. If they're super simple and don't have types...you can probably do without them and implement the lib yourself.
  3. You control the linter. You decide what ruleset makes sense. If you agree with this rule, use it, if not, don't.
  4. This is useless. Browser console error implies an actual runtime error, which is unacceptable, but you don't describe what's actually wrong, and your example is so broken that it could be anything.
  5. I'm still not sure of what the main idea here is...you want to wrap a component without passing all the props? 🤷
Masood Ahmad
@sircle:matrix.org
[m]
@keithlayne: thanks. my fellow dev was lazy i guess and didn't wanted to give types everytime and used ..spread for overlapping ones
Salathiel Genèse
@SalathielGenese
DRY (Don't Repeat Yourself principle) vs. Laziness
Abdul Azeez
@thisisazeez
Hi am new here and also with TypeScript
all resources I have are not worth it pls if I can have some you know correct resources
Salathiel Genèse
@SalathielGenese
TypeScript official website docs
Learn by practice
Don't suppose you understand: try it out and see for yourself
Copy/pasting don't help learning... Wrte it down yourself
Masood Ahmad
@sircle:matrix.org
[m]
@SalathielGenese: agreed 100%
Masood Ahmad
@sircle:matrix.org
[m]
@SalathielGenese: but if you see my case in https://pastebin.mozilla.org/vr6ynGxv#L33,52 if ..spread is not used, params will have to be repeated. And it seems that repetition should 'not' be avoided for good reasons as @keithlayne said.
Mayank Aggarwal
@Mayank0255_twitter
https://twitter.com/Mayank0255
Soon will start sharing some dev related stuff🎉