Ink: TypeScript definitions

Created on 4 Jul 2017  路  17Comments  路  Source: vadimdemedes/ink

Hi, just wanted to stop by and leave a comment to tell you how awesome I think this package is. I've been messing around with it, and decided to try doing something with it with typescript and redux.

I've pushed ink-typescript-redux-test which is essentially the Counter example, but with more awesomeness.

  • I've created a basic typescript definition for ink, contained in the custom_typings/ink directory.
  • Uses redux for state
  • Uses typescript-fsa for action creators and typescript-fsa-reducers for the reducer

If you want to include the typings in your project, feel free.

help wanted

Most helpful comment

Yeah, no problem! Drop me a line if you want help with it, or if you want to write the whole thing in Typescript (which would eliminate the need to maintain separate bindings :), lol)

All 17 comments

Hi, just wanted to stop by and leave a comment to tell you how awesome I think this package is. I've been messing around with it, and decided to try doing something with it with typescript and redux.

Thank you as well, comments like this are a rare and super exciting occasion for OSS maintainers 馃挋

As for TypeScript typings, I'd be more than happy to support them, but at a bit later point, since the package is in its very early stages and I expect the render/mount API to change. The component API (from React) isn't going to change though, just to clarify.

If you'd be willing to help in the near future, I can ping you later :)

Yeah, no problem! Drop me a line if you want help with it, or if you want to write the whole thing in Typescript (which would eliminate the need to maintain separate bindings :), lol)

@vadimdemedes Are you open to this being done now?

Yeah, sure.

@vadimdemedes I extended the TypeScript definitions @xdave originally wrote for a project I'm working on. Should I open a pull request?

@sindresorhus I had to manually duplicate the property and method types from Chalk, since the types are exported under a class. If Chalk refactored it's own type definitions to export the properties and methods as an interface, I would prefer to use that to keep the projects in sync.

What I mean is that there are types under the Chalk interface that are for a class.

import { Chalk } from "chalk/types";
export class Text extends Component<Partial<Chalk>, {}> {}

Ends up not being assignable when using:

return <Text green={true}>{`${this.state.i} tests passed`}</Text>;

Why don't we rewrite all in TypeScript?

Why don't we rewrite all in TypeScript?

I'm not a fan.

What's the issue with providing definitions?

i've started some work here.
For now, there is a port of progress-bar and divider + flexbox and chalk (a bit hacky) typings.

after switching to v2 I was able to run react-router and normal react typings so it is huge step forward to me. @vadimdemedes - thanks for this move 馃憤

more details here.

What's the issue with providing definitions?

from my point of view no issue, however if you are introducing component and there are only prop-types defined, it is a bit painful in ts - would be easier to have this in place, and apply changes when necessary around this repo, especially that complexity of cli apps is growing and it is better to have static type check over runtime.

If I'm working with some-pkg and notice that its' type defs are outdated, I'll usually try to fix them. However, if the typedefs are provided by @types/some-pkg which means the definitions are stored in DefinitelyTyped/DefinitelyTyped I won't even bother, I'll create a new file in ./type-stubs containing just declare module 'some-pkg'; and say f馃帀ck it. Because a) that repo won't even load in my browser because there's so many files in it b) the people there are snobby about writing tests even for minor changes c) the issues/PR sections have issues/PRs from thousands of other packages and my changes get drowned out

That's why I prefer typedefs be kept in the same repo as the projects source. If I PR a change, somebody will (usually) merge it pretty quickly.

/ rant

I've already written some (rough) type defs for v2 and would be happy to PR them AND keep them updated.

@rozzzly Awesome! Try to follow this style guide: https://github.com/sindresorhus/typescript-definition-style-guide

@rozzzly would you be able to put together that PR? Happy to chip in if you want some help

Opened up a PR with the changes I had to make locally to make it compile against @rozzzly's typings: https://github.com/rozzzly/template-ts-jest-webpack/pull/1

I've opened up #136 as a start

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JakeDawkins picture JakeDawkins  路  4Comments

goliney picture goliney  路  4Comments

zkat picture zkat  路  7Comments

asadm picture asadm  路  5Comments

isaacs picture isaacs  路  4Comments