Skip to content

Conversation

@KaneFreeman
Copy link
Member

@KaneFreeman KaneFreeman commented Jul 26, 2019

Type: feature

The following has been addressed in the PR:

Description:

Improve argument and return typing on icache middleware's getOrSet method.

This is completely a typing change with no implementation changes.

Before:

icache.getOrSet('test', 'test'); /* Type: any */
icache.getOrSet('test', () => 'test'); /* Type: any */
icache.getOrSet('test', () => Promise.resolve()); /* Type: any */
	
icache.getOrSet<string>('test', 'test'); /* Type: string | undefined */
icache.getOrSet<string>('test', 42); /* No Error, Type: string | undefined */
icache.getOrSet<string>('test', () => 'test'); /* Type: string | undefined */
icache.getOrSet<string>('test', () => Promise.resolve()); /* Type: string | undefined */

After:

icache.getOrSet('test', 'test'); /* Type: 'test' */
icache.getOrSet('test', () => 'test'); /* Type: string */
icache.getOrSet('test', () => Promise.resolve()); /* Type: undefined */

icache.getOrSet<string>('test', 'test'); /* Type: string */
icache.getOrSet<string>('test', 42); /* Type error: '42' is not assignable to parameter of type 'string' */
icache.getOrSet<string>('test', () => 'test'); /* Type: string */
icache.getOrSet<string>('test', () => Promise.resolve()); /* Type error: '() => Promise<void>' is not assignable to parameter of type 'string' */
icache.getOrSet<string>('test', () => new Promise<string>(() => {})); /* Type: undefined */

@KaneFreeman KaneFreeman requested review from agubler and matt-gadd July 26, 2019 15:44
@matt-gadd
Copy link
Contributor

@KaneFreeman nice! 👍

@matt-gadd matt-gadd merged commit 950a6b3 into dojo:master Jul 30, 2019
@KaneFreeman KaneFreeman deleted the icache-getorset-typing branch August 2, 2019 13:09
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