Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seamless-immutable type definition file #11717

Merged
merged 6 commits into from
Oct 6, 2016

Conversation

alex3165
Copy link
Contributor

@alex3165 alex3165 commented Oct 4, 2016

case 1. Add a new type definition.

  • checked compilation succeeds with --target es6 and --noImplicitAny options.
  • has correct naming convention
  • has a test file with the suffix of -tests.ts or -tests.tsx.

case 2. Improvement to existing type definition.

  • documentation or source code reference which provides context for the suggested changes. url http://api.jquery.com/html .
    • it has been reviewed by a DefinitelyTyped member.

@dt-bot
Copy link
Member

dt-bot commented Oct 4, 2016

seamless-immutable/seamless.d.ts

Checklist

@@ -0,0 +1,83 @@
// Type definitions for Seamless-immutable 6.1.3
// Project: https://github.com/rtfeldman/seamless-immutable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file name should be seamless-immutable\seamless-immutable.d.ts

// Definitions by: alex3165 <https://github.com/alex3165>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// Copyright (c) 2016, Richard Feldman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For legal reasons, we can not have different licence text for packages. all packages use the MIT licence under: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/LICENSE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we will not be able to accept this PR as long as it has this specialized licence text.

merge(part: any, config?: MergeConfig): ImmutableObject<T>;

update(property: string, updaterFunction: (value: any) => any): ImmutableObject<T>;
update(property: string, updaterFunction: (value: any, additionalParameter1: any) => any, arg1: any): ImmutableObject<T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend changing these into one signature with rest args:

update(property: string, updaterFunction: (value: any, ...additionalParamters: any[]) => any, ...additionalArguments: any[]): ImmutableObject<T>;

updateIn(propertyPath: Array<string>, updaterFunction: (value: any, additionalParameter1: any, additionalParameter2: any, additionalParameter3: any) => any, arg1: any, arg2: any, arg3: any): ImmutableObject<T>;
updateIn(propertyPath: Array<string>, updaterFunction: (value: any, additionalParameter1: any, additionalParameter2: any, additionalParameter3: any, additionalParameter4: any) => any, arg1: any, arg2: any, arg3: any): ImmutableObject<T>;

without(property: string): ImmutableObject<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already covered by without(...properties: string[]): ImmutableObject<any>;

@alex3165
Copy link
Contributor Author

alex3165 commented Oct 5, 2016

@mhegazy Thank you for your advice I have made the changes.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 5, 2016

thanks. can you please address the failing CI tests.

@alex3165
Copy link
Contributor Author

alex3165 commented Oct 6, 2016

@mhegazy Fixed

@mhegazy mhegazy merged commit f3a936c into DefinitelyTyped:master Oct 6, 2016
@toranb
Copy link

toranb commented May 18, 2017

Anyone have an example app using this w/ TS 2x ? Just looking around for some samples to see how you would import and use use something like SI.ImmutableObject with ES2015+ syntax and TS 2.1

note: mostly asking because I ran into this error building a TS 2.1 app using this type def

import Immutable from 'seamless-immutable';

const initialState = Immutable({
});
Cannot invoke an expression whose type lacks a call signature. Type 'typeof SeamlessImmutable' has no compatible call signatures.

@types/seamless-immutable v6.1.2

UPDATE

I was able to get this working by altering my import like so

import * as SI from 'seamless-immutable';

const initialState = SI.from({
});

My first pass at typescript + seamless immutable (along with redux/and emberJS) for those who may find this later. I had to do an interesting hack to get this working (note this toward the top of the file)

toranb/ember-redux-yelp@0fe9bfa

import * as SI from 'seamless-immutable';

const Immutable = SI['default'] ? SI['default'] : SI;

const initialState = Immutable({
});

UPDATE July 2017

I ended up writing a set of type defs for seamless-immutable 7

https://github.com/toranb/seamless-immutable-tsdefs

I've had success writing product types like you see below

import { ImmutableObject } from 'seamless-immutable';

type ImmutableState<T> = ImmutableObject<T> & T;

export default ((state: ImmutableState<UserState>, action: Action): ImmutableState<UserState> => {
  switch(action.type) {
    case 'ASSIGN_USER': {
      return state.merge({number: action.number});
    }
    default: {
      return state || initialState;
    }
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants