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

upgrade typescript to 3.1.3 & replace strict mapping to partial in calledWith function #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tommy20061222
Copy link

@tommy20061222 tommy20061222 commented Oct 31, 2018

Hey, Matt,
Initially I want to use this PR to address the following issue:
` type attributeList = 'foo' | 'bar' | 'foobar';
type attributeUpdate = {
[P in K]: string;
}

            const testedTarget = {
                foo: 'fooVal',
                bar: 'barVal',
            }

            interface alienService {
                updateAlienAttribute<K extends attributeList>(attributes: attributeUpdate<K>): void
            }

            const mock: Mock<alienService> = SafeMock.build<alienService>();
            mock.updateAlienAttribute(testedTarget);
            // without partial put int he index.d.ts, following line does not compile
            verify(mock.updateAlienAttribute).calledWith(testedTarget);`

Without this PR, it has compile error on lastline. After a little bit playground, i found this break is introduced in typescript 2.7 by this break change: link

Furthermore, this PR also upgrade typescript to latest 3.1.3 version.

@matthewmcnew
Copy link
Owner

HI @tommy20061222 ,

I went ahead and merged your upgrade to typescript 3.1.3 to master (b0ace79). Looks good.

I wanted to get a better understanding of your use case for the PR.

Would it work to use the record type like:

interface alienService {
updateAlienAttribute(attributes: Record<'foo' | 'bar' | 'foobar', string>): void
}

I am a bit afraid that adding 'Partial' to the Call Verify signature will have some unattended consequences with a regression in the type safety. This is because: Partial is not the same thing as K.

  • Cheers!

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.

2 participants