Skip to content

Add NoInfer intrinsic type - #52968

Closed
Mateusz Burzyński (Andarist) wants to merge 7 commits into
microsoft:mainfrom
Andarist:noinfer
Closed

Add NoInfer intrinsic type#52968
Mateusz Burzyński (Andarist) wants to merge 7 commits into
microsoft:mainfrom
Andarist:noinfer

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

closes#14829

There is still some work to be done here (type displays on hover, assignability bug, and maybe more) - but I'm pushing this out to receive an early feedback

cc Ryan Cavanaugh (@RyanCavanaugh)

@typescript-bot

Copy link
Copy Markdown
Contributor

The TypeScript team hasn't accepted the linked issue #14829. If you can get it accepted, this PR will have a better chance of being reviewed.

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 25, 2023
Comment threadtests/baselines/reference/noInfer.errors.txt Outdated
@sandersn

Copy link
Copy Markdown
Member

Mateusz Burzyński (@Andarist) did you learn anything interesting from the implementation? If so, can you add a report to the end of #14829? Unless Daniel Rosenwasser (@DanielRosenwasser)Ryan Cavanaugh (@RyanCavanaugh) or Anders Hejlsberg (@ahejlsberg) are interested in taking up this feature in a design meeting, it's likely that this PR will sit until it gets stale.

@Andarist

Copy link
Copy Markdown
ContributorAuthor

Jake Bailey (@jakebailey) would you mind creating a playground for this? :)

@jakebailey

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the tarball bundle task on this PR at 86448ff. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/149238/artifacts?artifactName=tgz&fileId=E040D91AAAB70FE622A8C39FD6DF27B76C392A7C8C3B48C212D760AAF66AFD4702&fileName=/typescript-5.1.0-insiders.20230313.tgz"
}
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.1.0-pr-52968-5".;

@unional

Copy link
Copy Markdown
Contributor

Hi, I am reading #14829 and trying to add NoInfer<T> to fix the stub() function in type-plus.

An I notice the type type NoInfer<T> = T & { [K in keyof T]: T[K] } there works with the Animal|Dog example but does not work with:

typeNoInfer<T>=T&{[KinkeyofT]: T[K]}typeRecursivePartial<T>={[PinkeyofT]?: T[P]extends(infer U)[]
? RecursivePartial<U>[]
: T[P]extendsRecord<any,any>
? RecursivePartial<T[P]>
: T[P]}functionfoo(v: {a: number,b: string}){}functionstub<T>(v: RecursivePartial<NoInfer<T>>): T{returnvasT}foo(stub({a: 1})// error// Argument of type '{ a: number; }' is not assignable to parameter of type '{ a: number; b: string; }'.// Property 'b' is missing in type '{ a: number; }' but required in type '{ a: number; b: string; }'.

It works with the following type: type NoInfer<T> = Or<IsNull<T>, IsUndefined<T>, T, T & {}>
(where Or<A,B,Then,Else>, IsNull<T>, IsUndefined<T> does what their name suggest).

Just want to bring it up so that this test case is covered in your implementation.
🌷

@Andarist

Copy link
Copy Markdown
ContributorAuthor

Ryan Cavanaugh (@RyanCavanaugh) Since 5.2 development has started recently - perhaps we could get some current thoughts from the team about this feature? 😉

@andrewbranch

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

Copy link
Copy Markdown
Contributor

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure Daniel Rosenwasser (@DanielRosenwasser) and Ryan Cavanaugh (@RyanCavanaugh) are aware of the changes, just as a heads up.

@typescript-bot

TypeScript Bot (typescript-bot) commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

Heya Andrew Branch (@andrewbranch), I've started to run the tarball bundle task on this PR at 989fa50. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

Hey Andrew Branch (@andrewbranch), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/158991/artifacts?artifactName=tgz&fileId=95BBFD2778E2B6F0853A6F2EF1EAB1A4AF470C0AB105BAD2C44C6707C2F2A1D302&fileName=/typescript-5.4.0-insiders.20231207.tgz"
}
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.4.0-pr-52968-11".;

@Andarist

Copy link
Copy Markdown
ContributorAuthor

superseded by #56794

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Suggestion: Noninferential type parameter usage

6 participants

@Andarist@typescript-bot@sandersn@jakebailey@unional@andrewbranch